Tikz-pgfplots 和 matlab2tikz 不能很好地捕捉子图

Tikz-pgfplots 和 matlab2tikz 不能很好地捕捉子图

我使用 matlab2tikz 来转换这个 matrlab 图形:

在此处输入图片描述

% This file was created by matlab2tikz v0.3.3.
% Copyright (c) 2008--2013, Nico Schlömer <[email protected]>
% All rights reserved.
%
% The latest updates can be retrieved from
% http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.
%

\documentclass[tikz,border=12pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}


\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.05,
xmax=0.1,
ymin=0,
ymax=0.5,
name=plot7
]
\addplot[ybar,bar width=0.043288829176002in,fill=red,draw=black] plot coordinates{(0.0659000695687248,0.021)
(0.0692598417336974,0.17)
(0.07261961389867,0.433)
(0.0759793860636426,0.309)
(0.0793391582286153,0.062)
(0.0826989303935879,0.005)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.05 0\\
0.1 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.3,
xmax=0.34,
ymin=0,
ymax=0.4,
name=plot2,
at=(plot7.above north west),
anchor=below south west
]
\addplot[ybar,bar width=0.0807059488901532in,fill=red,draw=black] plot coordinates{(0.312222366574404,0.039)
(0.31723342565436,0.155)
(0.322244484734316,0.378)
(0.327255543814272,0.307)
(0.332266602894228,0.105)
(0.337277661974184,0.016)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.3 0\\
0.34 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.1,
xmax=0.2,
ymin=0,
ymax=0.5,
ylabel={1},
name=plot1,
at=(plot2.left of south west),
anchor=right of south east
]
\addplot[ybar,bar width=0.0324834334482669in,fill=red,draw=black] plot coordinates{(0.139343693974076,0.001)
(0.14438596181082,0.042)
(0.149428229647564,0.311)
(0.154470497484307,0.448)
(0.159512765321051,0.168)
(0.164555033157795,0.03)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.1 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.25,
xmax=0.35,
ymin=0,
ymax=0.5,
ylabel={6},
name=plot6,
at=(plot1.below south west),
anchor=above north west
]
\addplot[ybar,bar width=0.032005621766854in,fill=red,draw=black] plot coordinates{(0.279030441314133,0.007)
(0.283998540437245,0.076)
(0.288966639560357,0.343)
(0.293934738683469,0.401)
(0.298902837806581,0.159)
(0.303870936929693,0.014)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.25 0\\
0.35 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.05,
xmax=0.1,
ymin=0,
ymax=0.4,
ylabel={11},
name=plot11,
at=(plot6.below south west),
anchor=above north west
]
\addplot[ybar,bar width=0.0405914330775104in,fill=red,draw=black] plot coordinates{(0.078219549216173,0.021)
(0.0813699686104164,0.147)
(0.0845203880046599,0.388)
(0.0876708073989033,0.323)
(0.0908212267931467,0.112)
(0.0939716461873902,0.009)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.05 0\\
0.1 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.04,
xmax=0.08,
ymin=0,
ymax=0.5,
name=plot12,
at=(plot11.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0462259046537809in,fill=red,draw=black] plot coordinates{(0.0463714494657005,0.012)
(0.0492416311862549,0.077)
(0.0521118129068092,0.356)
(0.0549819946273635,0.411)
(0.0578521763479179,0.131)
(0.0607223580684722,0.013)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.04 0\\
0.08 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.2,
xmax=0.25,
ymin=0,
ymax=0.5,
name=plot13,
at=(plot12.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0730544427651677in,fill=red,draw=black] plot coordinates{(0.211738394333697,0.01)
(0.217408362498741,0.075)
(0.223078330663786,0.282)
(0.228748298828831,0.403)
(0.234418266993876,0.199)
(0.240088235158921,0.031)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.2 0\\
0.25 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.15,
xmax=0.2,
ymin=0,
ymax=0.4,
name=plot8,
at=(plot13.above north west),
anchor=below south west
]
\addplot[ybar,bar width=0.0668055798190288in,fill=red,draw=black] plot coordinates{(0.171594427925392,0.031)
(0.176779403629591,0.148)
(0.181964379333791,0.357)
(0.187149355037991,0.337)
(0.192334330742191,0.108)
(0.197519306446391,0.019)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.15 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0,
xmax=0.2,
ymin=0,
ymax=0.4,
name=plot3,
at=(plot8.above north west),
anchor=below south west
]
\addplot[ybar,bar width=0.0137654862069659in,fill=red,draw=black] plot coordinates{(0.0789465232970514,0.027)
(0.0832200412716255,0.176)
(0.0874935592461996,0.374)
(0.0917670772207738,0.301)
(0.0960405951953479,0.108)
(0.100314113169922,0.014)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.1,
xmax=0.2,
ymin=0,
ymax=0.4,
name=plot4,
at=(plot3.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0196957918910425in,fill=red,draw=black] plot coordinates{(0.125971343837049,0.023)
(0.129028639431419,0.144)
(0.132085935025789,0.333)
(0.135143230620159,0.341)
(0.13820052621453,0.135)
(0.1412578218089,0.024)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.1 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.15,
xmax=0.25,
ymin=0,
ymax=0.4,
name=plot5,
at=(plot4.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0313998614316301in,fill=red,draw=black] plot coordinates{(0.191265032044859,0.011)
(0.196139101518675,0.098)
(0.201013170992491,0.304)
(0.205887240466306,0.4)
(0.210761309940122,0.158)
(0.215635379413938,0.029)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.15 0\\
0.25 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.1,
xmax=0.2,
ymin=0,
ymax=0.4,
name=plot10,
at=(plot5.below south west),
anchor=above north west
]
\addplot[ybar,bar width=0.0224254755366411in,fill=red,draw=black] plot coordinates{(0.140368517931761,0.028)
(0.143849530928807,0.179)
(0.147330543925853,0.393)
(0.150811556922899,0.304)
(0.154292569919945,0.087)
(0.15777358291699,0.009)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.1 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.2,
xmax=0.25,
ymin=0,
ymax=0.4,
name=plot9,
at=(plot10.left of south west),
anchor=right of south east
]
\addplot[ybar,bar width=0.0405693776939796in,fill=red,draw=black] plot coordinates{(0.207344946966133,0.017)
(0.210493654577797,0.129)
(0.213642362189461,0.328)
(0.216791069801125,0.349)
(0.219939777412789,0.152)
(0.223088485024453,0.025)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.2 0\\
0.25 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.05,
xmax=0.1,
ymin=0,
ymax=0.4,
name=plot14,
at=(plot9.below south west),
anchor=above north west
]
\addplot[ybar,bar width=0.0331461479267899in,fill=red,draw=black] plot coordinates{(0.079766376675645,0.03)
(0.0823389457956763,0.175)
(0.0849115149157076,0.382)
(0.0874840840357389,0.312)
(0.0900566531557703,0.091)
(0.0926292222758016,0.01)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.05 0\\
0.1 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.1,
xmax=0.2,
ymin=0,
ymax=0.5,
name=plot15,
at=(plot14.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0246002237715389in,fill=red,draw=black] plot coordinates{(0.125493229134264,0.017)
(0.129311819225656,0.152)
(0.133130409317048,0.415)
(0.136948999408439,0.319)
(0.140767589499831,0.09)
(0.144586179591223,0.007)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.1 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.26,
xmax=0.3,
ymin=0,
ymax=0.5,
name=plot20,
at=(plot15.below south west),
anchor=above north west
]
\addplot[ybar,bar width=0.0806393672293079in,fill=red,draw=black] plot coordinates{(0.270813181120336,0.05)
(0.275820106122932,0.205)
(0.280827031125528,0.407)
(0.285833956128124,0.268)
(0.29084088113072,0.064)
(0.295847806133316,0.006)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.26 0\\
0.3 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.34,
xmax=0.38,
ymin=0,
ymax=0.4,
name=plot19,
at=(plot20.left of south west),
anchor=right of south east
]
\addplot[ybar,bar width=0.065694577498781in,fill=red,draw=black] plot coordinates{(0.349854667287936,0.056)
(0.353933665349494,0.24)
(0.358012663411053,0.378)
(0.362091661472611,0.254)
(0.366170659534169,0.067)
(0.370249657595727,0.005)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.34 0\\
0.38 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.25,
xmax=0.35,
ymin=0,
ymax=0.4,
name=plot18,
at=(plot19.left of south west),
anchor=right of south east
]
\addplot[ybar,bar width=0.0430237470219284in,fill=red,draw=black] plot coordinates{(0.291221051492245,0.015)
(0.297899448225471,0.108)
(0.304577844958698,0.311)
(0.311256241691924,0.388)
(0.31793463842515,0.157)
(0.324613035158376,0.021)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.25 0\\
0.35 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.3,
xmax=0.5,
ymin=0,
ymax=0.4,
name=plot17,
at=(plot18.left of south west),
anchor=right of south east
]
\addplot[ybar,bar width=0.0171744242069946in,fill=red,draw=black] plot coordinates{(0.380628398764973,0.03)
(0.385960227183385,0.131)
(0.391292055601797,0.326)
(0.396623884020208,0.34)
(0.40195571243862,0.145)
(0.407287540857031,0.028)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.3 0\\
0.5 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.15,
xmax=0.25,
ymin=0,
ymax=0.5,
ylabel={16},
name=plot16,
at=(plot17.left of south west),
anchor=right of south east
]
\addplot[ybar,bar width=0.0319153516452449in,fill=red,draw=black] plot coordinates{(0.198752777878067,0.021)
(0.203706864746854,0.203)
(0.208660951615642,0.405)
(0.213615038484429,0.305)
(0.218569125353217,0.06)
(0.223523212222004,0.006)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.15 0\\
0.25 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.24,
xmax=0.28,
xlabel={21},
ymin=0,
ymax=0.4,
ylabel={21},
name=plot21,
at=(plot16.below south west),
anchor=above north west
]
\addplot[ybar,bar width=0.0826788173542177in,fill=red,draw=black] plot coordinates{(0.246435987377215,0.018)
(0.251569542513117,0.16)
(0.256703097649019,0.388)
(0.261836652784921,0.32)
(0.266970207920823,0.103)
(0.272103763056725,0.011)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.24 0\\
0.28 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.1,
xmax=0.2,
xlabel={22},
ymin=0,
ymax=0.4,
name=plot22,
at=(plot21.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0228819133882036in,fill=red,draw=black] plot coordinates{(0.145570415955891,0.03)
(0.149122279896144,0.123)
(0.152674143836397,0.296)
(0.15622600777665,0.351)
(0.159777871716902,0.163)
(0.163329735657155,0.037)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.1 0\\
0.2 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.15,
xmax=0.25,
xlabel={23},
ymin=0,
ymax=0.4,
name=plot23,
at=(plot22.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0341745271860721in,fill=red,draw=black] plot coordinates{(0.179222206561426,0.039)
(0.184526975822985,0.224)
(0.189831745084544,0.394)
(0.195136514346103,0.256)
(0.200441283607662,0.079)
(0.205746052869221,0.008)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.15 0\\
0.25 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.15,
xmax=0.25,
xlabel={24},
ymin=0,
ymax=0.4,
name=plot24,
at=(plot23.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.021268709273948in,fill=red,draw=black] plot coordinates{(0.199144460834193,0.02)
(0.202445913830899,0.154)
(0.205747366827605,0.377)
(0.209048819824311,0.337)
(0.212350272821017,0.098)
(0.215651725817723,0.014)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.15 0\\
0.25 0\\
};
\end{axis}

\begin{axis}[%
width=0.805278361344538in,
height=0.57402895480226in,
area legend,
scale only axis,
xmin=0.2,
xmax=0.25,
xlabel={25},
ymin=0,
ymax=0.4,
at=(plot24.right of south east),
anchor=left of south west
]
\addplot[ybar,bar width=0.0538644920254994in,fill=red,draw=black] plot coordinates{(0.22154662783444,0.019)
(0.22572720800795,0.167)
(0.22990778818146,0.37)
(0.23408836835497,0.315)
(0.238268948528481,0.113)
(0.242449528701991,0.016)};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.2 0\\
0.25 0\\
};
\end{axis}
\end{tikzpicture}%
\end{document}

然而这使得:

在此处输入图片描述 图未对齐,建议的解决方案为:

在 pgfplots 图中对齐子图 没有帮助。还有没有办法让末尾的 xtick 和 ytick 标记像在 matlab 中一样出现?或者我应该直接复制并粘贴该图?

答案1

pgplots只需在序言中添加此设置即可

\pgfplotsset{every axis/.append style={%
    scaled x ticks=false,
    scaled y ticks=false,
    yticklabel style={/pgf/number format/.cd,fixed,fixed zerofill,precision=1},
    xticklabel style={/pgf/number format/.cd,fixed,fixed zerofill,precision=2},
    ytick={\pgfkeysvalueof{/pgfplots/ymax},\pgfkeysvalueof{/pgfplots/ymin}},
    xtick={\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/xmin}}}}

前两个选项禁止轴标签使用共同的乘积因子。

第三和第四个选项用于为所有标签设置相同的精度,以便每个图形具有相同的宽度并且对齐良好。

最后两个选项仅设置xtick相应ytick轴的最大值和最小值。

在此处输入图片描述

相关内容