matlab2tikz / matlab2tikz

This program converts MATLAB®/Octave figures to TikZ/pgfplots figures for smooth integration into LaTeX.
http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
BSD 2-Clause "Simplified" License
1.53k stars 316 forks source link

Picture partially visible with noSize option #1094

Open desk7 opened 3 years ago

desk7 commented 3 years ago

I created this simple figure with 2 subplot. Without noSize option the code is

F= figure('Name', 'Ciao');
x=1:0.1:10;
y=sin(x);
z=cos(x);
subplot(121)
plot(x,y)
subplot(122)
plot(x,z)

matlab2tikz('filename','aaa.tikz');

The Latex MWE is:

\documentclass{article} 
\usepackage{pgfplots, subfig, tikz, tikzscale}
\pgfplotsset{compat=newest} 
\pgfplotsset{plot coordinates/math parser=false} 
\usetikzlibrary{arrows.meta}
\newlength\figureheight 
\newlength\figurewidth 
\usepackage{euler}
\begin{document} 
\begin{figure}
    \centering
 \includegraphics[width=.7\textwidth]{aaa.tikz}
    \caption{didascalia}
\end{figure}

where I use the tikzscale for scaling the tikz picture. The output file is:

% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
%
\begin{tikzpicture}

\begin{axis}[%
width=1.952in,
height=3.566in,
at={(0.758in,0.481in)},
scale only axis,
xmin=0,
xmax=10,
ymin=-1,
ymax=1,
axis background/.style={fill=white}
]
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
1   0.841470984807897\\
1.1 0.891207360061435\\
1.2 0.932039085967226\\
1.3 0.963558185417193\\
1.4 0.98544972998846\\
1.5 0.997494986604054\\
1.6 0.999573603041505\\
1.7 0.991664810452469\\
1.8 0.973847630878195\\
1.9 0.946300087687414\\
2   0.909297426825682\\
2.1 0.863209366648874\\
2.2 0.80849640381959\\
2.3 0.74570521217672\\
2.4 0.675463180551151\\
2.5 0.598472144103956\\
2.6 0.515501371821464\\
2.7 0.42737988023383\\
2.8 0.334988150155905\\
2.9 0.239249329213982\\
3   0.141120008059867\\
3.1 0.0415806624332905\\
3.2 -0.0583741434275801\\
3.3 -0.157745694143249\\
3.4 -0.255541102026832\\
3.5 -0.35078322768962\\
3.6 -0.442520443294852\\
3.7 -0.529836140908493\\
3.8 -0.611857890942719\\
3.9 -0.687766159183974\\
4   -0.756802495307928\\
4.1 -0.81827711106441\\
4.2 -0.871575772413588\\
4.3 -0.916165936749455\\
4.4 -0.951602073889516\\
4.5 -0.977530117665097\\
4.6 -0.993691003633464\\
4.7 -0.999923257564101\\
4.8 -0.996164608835841\\
4.9 -0.982452612624332\\
5   -0.958924274663138\\
5.1 -0.925814682327732\\
5.2 -0.883454655720153\\
5.3 -0.832267442223901\\
5.4 -0.772764487555987\\
5.5 -0.705540325570392\\
5.6 -0.631266637872322\\
5.7 -0.550685542597638\\
5.8 -0.464602179413757\\
5.9 -0.373876664830237\\
6   -0.279415498198926\\
6.1 -0.182162504272096\\
6.2 -0.0830894028174973\\
6.3 0.0168139004843497\\
6.4 0.116549204850494\\
6.5 0.215119988087816\\
6.6 0.311541363513378\\
6.7 0.404849920616598\\
6.8 0.494113351138608\\
6.9 0.5784397643882\\
7   0.656986598718789\\
7.1 0.728969040125876\\
7.2 0.793667863849153\\
7.3 0.850436620628564\\
7.4 0.898708095811627\\
7.5 0.937999976774739\\
7.6 0.967919672031486\\
7.7 0.988168233877\\
7.8 0.998543345374605\\
7.9 0.998941341839772\\
8   0.989358246623382\\
8.1 0.969889810845086\\
8.2 0.940730556679773\\
8.3 0.902171833756293\\
8.4 0.854598908088281\\
8.5 0.79848711262349\\
8.6 0.734397097874113\\
8.7 0.662969230082183\\
8.8 0.584917192891762\\
8.9 0.501020856457885\\
9   0.412118485241757\\
9.1 0.319098362349352\\
9.2 0.222889914100248\\
9.3 0.124454423507062\\
9.4 0.0247754254533578\\
9.5 -0.0751511204618093\\
9.6 -0.17432678122298\\
9.7 -0.271760626410942\\
9.8 -0.366479129251928\\
9.9 -0.457535893775321\\
10  -0.54402111088937\\
};
\end{axis}

\begin{axis}[%
width=1.952in,
height=3.566in,
at={(3.327in,0.481in)},
scale only axis,
xmin=0,
xmax=10,
ymin=-1,
ymax=1,
axis background/.style={fill=white}
]
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
1   0.54030230586814\\
1.1 0.453596121425577\\
1.2 0.362357754476674\\
1.3 0.267498828624587\\
1.4 0.169967142900241\\
1.5 0.0707372016677029\\
1.6 -0.0291995223012888\\
1.7 -0.128844494295525\\
1.8 -0.227202094693087\\
1.9 -0.323289566863503\\
2   -0.416146836547142\\
2.1 -0.504846104599858\\
2.2 -0.588501117255346\\
2.3 -0.666276021279824\\
2.4 -0.737393715541246\\
2.5 -0.801143615546934\\
2.6 -0.856888753368947\\
2.7 -0.904072142017061\\
2.8 -0.942222340668658\\
2.9 -0.970958165149591\\
3   -0.989992496600445\\
3.1 -0.999135150273279\\
3.2 -0.998294775794753\\
3.3 -0.987479769908865\\
3.4 -0.966798192579461\\
3.5 -0.936456687290796\\
3.6 -0.896758416334147\\
3.7 -0.848100031710408\\
3.8 -0.790967711914417\\
3.9 -0.72593230420014\\
4   -0.653643620863612\\
4.1 -0.574823946533269\\
4.2 -0.490260821340699\\
4.3 -0.400799172079975\\
4.4 -0.307332869978419\\
4.5 -0.21079579943078\\
4.6 -0.112152526935055\\
4.7 -0.0123886634628906\\
4.8 0.0874989834394473\\
4.9 0.186512369422576\\
5   0.283662185463226\\
5.1 0.377977742712981\\
5.2 0.468516671300377\\
5.3 0.554374336179161\\
5.4 0.634692875942635\\
5.5 0.70866977429126\\
5.6 0.77556587851025\\
5.7 0.83471278483916\\
5.8 0.885519516941319\\
5.9 0.927478430744036\\
6   0.960170286650366\\
6.1 0.983268438442584\\
6.2 0.996542097023217\\
6.3 0.999858636383415\\
6.4 0.993184918758193\\
6.5 0.976587625728023\\
6.6 0.95023259195853\\
6.7 0.91438314823532\\
6.8 0.869397490349825\\
6.9 0.815725100125357\\
7   0.753902254343305\\
7.1 0.684546666442807\\
7.2 0.608351314532255\\
7.3 0.526077517381105\\
7.4 0.43854732757439\\
7.5 0.346635317835026\\
7.6 0.251259842582256\\
7.7 0.153373862037865\\
7.8 0.0539554205626498\\
7.9 -0.0460021256395369\\
8   -0.145500033808614\\
8.1 -0.243544153735791\\
8.2 -0.339154860983835\\
8.3 -0.431376844970621\\
8.4 -0.519288654116686\\
8.5 -0.602011902684824\\
8.6 -0.678720047320012\\
8.7 -0.748646645597399\\
8.8 -0.811093014061656\\
8.9 -0.865435209241112\\
9   -0.911130261884677\\
9.1 -0.947721602131112\\
9.2 -0.974843621404164\\
9.3 -0.992225325452603\\
9.4 -0.999693042035206\\
9.5 -0.997172156196378\\
9.6 -0.984687855794127\\
9.7 -0.96236487983131\\
9.8 -0.930426272104753\\
9.9 -0.889191152625361\\
10  -0.839071529076452\\
};
\end{axis}
\end{tikzpicture}%

The result is good:

a

I read that the noSize options is useful when tikzscale is used. So I tried:

F= figure('Name', 'Ciao');
x=1:0.1:10;
y=sin(x);
z=cos(x);
subplot(121)
plot(x,y)
subplot(122)
plot(x,z)

matlab2tikz('filename','aaa.tikz', 'noSize',true);

The output tikz picture is

% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
%
\begin{tikzpicture}

\begin{axis}[%
xmin=0,
xmax=10,
ymin=-1,
ymax=1,
axis background/.style={fill=white}
]
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
1   0.841470984807897\\
1.1 0.891207360061435\\
1.2 0.932039085967226\\
1.3 0.963558185417193\\
1.4 0.98544972998846\\
1.5 0.997494986604054\\
1.6 0.999573603041505\\
1.7 0.991664810452469\\
1.8 0.973847630878195\\
1.9 0.946300087687414\\
2   0.909297426825682\\
2.1 0.863209366648874\\
2.2 0.80849640381959\\
2.3 0.74570521217672\\
2.4 0.675463180551151\\
2.5 0.598472144103956\\
2.6 0.515501371821464\\
2.7 0.42737988023383\\
2.8 0.334988150155905\\
2.9 0.239249329213982\\
3   0.141120008059867\\
3.1 0.0415806624332905\\
3.2 -0.0583741434275801\\
3.3 -0.157745694143249\\
3.4 -0.255541102026832\\
3.5 -0.35078322768962\\
3.6 -0.442520443294852\\
3.7 -0.529836140908493\\
3.8 -0.611857890942719\\
3.9 -0.687766159183974\\
4   -0.756802495307928\\
4.1 -0.81827711106441\\
4.2 -0.871575772413588\\
4.3 -0.916165936749455\\
4.4 -0.951602073889516\\
4.5 -0.977530117665097\\
4.6 -0.993691003633464\\
4.7 -0.999923257564101\\
4.8 -0.996164608835841\\
4.9 -0.982452612624332\\
5   -0.958924274663138\\
5.1 -0.925814682327732\\
5.2 -0.883454655720153\\
5.3 -0.832267442223901\\
5.4 -0.772764487555987\\
5.5 -0.705540325570392\\
5.6 -0.631266637872322\\
5.7 -0.550685542597638\\
5.8 -0.464602179413757\\
5.9 -0.373876664830237\\
6   -0.279415498198926\\
6.1 -0.182162504272096\\
6.2 -0.0830894028174973\\
6.3 0.0168139004843497\\
6.4 0.116549204850494\\
6.5 0.215119988087816\\
6.6 0.311541363513378\\
6.7 0.404849920616598\\
6.8 0.494113351138608\\
6.9 0.5784397643882\\
7   0.656986598718789\\
7.1 0.728969040125876\\
7.2 0.793667863849153\\
7.3 0.850436620628564\\
7.4 0.898708095811627\\
7.5 0.937999976774739\\
7.6 0.967919672031486\\
7.7 0.988168233877\\
7.8 0.998543345374605\\
7.9 0.998941341839772\\
8   0.989358246623382\\
8.1 0.969889810845086\\
8.2 0.940730556679773\\
8.3 0.902171833756293\\
8.4 0.854598908088281\\
8.5 0.79848711262349\\
8.6 0.734397097874113\\
8.7 0.662969230082183\\
8.8 0.584917192891762\\
8.9 0.501020856457885\\
9   0.412118485241757\\
9.1 0.319098362349352\\
9.2 0.222889914100248\\
9.3 0.124454423507062\\
9.4 0.0247754254533578\\
9.5 -0.0751511204618093\\
9.6 -0.17432678122298\\
9.7 -0.271760626410942\\
9.8 -0.366479129251928\\
9.9 -0.457535893775321\\
10  -0.54402111088937\\
};
\end{axis}

\begin{axis}[%
xmin=0,
xmax=10,
ymin=-1,
ymax=1,
axis background/.style={fill=white}
]
\addplot [color=mycolor1, forget plot]
  table[row sep=crcr]{%
1   0.54030230586814\\
1.1 0.453596121425577\\
1.2 0.362357754476674\\
1.3 0.267498828624587\\
1.4 0.169967142900241\\
1.5 0.0707372016677029\\
1.6 -0.0291995223012888\\
1.7 -0.128844494295525\\
1.8 -0.227202094693087\\
1.9 -0.323289566863503\\
2   -0.416146836547142\\
2.1 -0.504846104599858\\
2.2 -0.588501117255346\\
2.3 -0.666276021279824\\
2.4 -0.737393715541246\\
2.5 -0.801143615546934\\
2.6 -0.856888753368947\\
2.7 -0.904072142017061\\
2.8 -0.942222340668658\\
2.9 -0.970958165149591\\
3   -0.989992496600445\\
3.1 -0.999135150273279\\
3.2 -0.998294775794753\\
3.3 -0.987479769908865\\
3.4 -0.966798192579461\\
3.5 -0.936456687290796\\
3.6 -0.896758416334147\\
3.7 -0.848100031710408\\
3.8 -0.790967711914417\\
3.9 -0.72593230420014\\
4   -0.653643620863612\\
4.1 -0.574823946533269\\
4.2 -0.490260821340699\\
4.3 -0.400799172079975\\
4.4 -0.307332869978419\\
4.5 -0.21079579943078\\
4.6 -0.112152526935055\\
4.7 -0.0123886634628906\\
4.8 0.0874989834394473\\
4.9 0.186512369422576\\
5   0.283662185463226\\
5.1 0.377977742712981\\
5.2 0.468516671300377\\
5.3 0.554374336179161\\
5.4 0.634692875942635\\
5.5 0.70866977429126\\
5.6 0.77556587851025\\
5.7 0.83471278483916\\
5.8 0.885519516941319\\
5.9 0.927478430744036\\
6   0.960170286650366\\
6.1 0.983268438442584\\
6.2 0.996542097023217\\
6.3 0.999858636383415\\
6.4 0.993184918758193\\
6.5 0.976587625728023\\
6.6 0.95023259195853\\
6.7 0.91438314823532\\
6.8 0.869397490349825\\
6.9 0.815725100125357\\
7   0.753902254343305\\
7.1 0.684546666442807\\
7.2 0.608351314532255\\
7.3 0.526077517381105\\
7.4 0.43854732757439\\
7.5 0.346635317835026\\
7.6 0.251259842582256\\
7.7 0.153373862037865\\
7.8 0.0539554205626498\\
7.9 -0.0460021256395369\\
8   -0.145500033808614\\
8.1 -0.243544153735791\\
8.2 -0.339154860983835\\
8.3 -0.431376844970621\\
8.4 -0.519288654116686\\
8.5 -0.602011902684824\\
8.6 -0.678720047320012\\
8.7 -0.748646645597399\\
8.8 -0.811093014061656\\
8.9 -0.865435209241112\\
9   -0.911130261884677\\
9.1 -0.947721602131112\\
9.2 -0.974843621404164\\
9.3 -0.992225325452603\\
9.4 -0.999693042035206\\
9.5 -0.997172156196378\\
9.6 -0.984687855794127\\
9.7 -0.96236487983131\\
9.8 -0.930426272104753\\
9.9 -0.889191152625361\\
10  -0.839071529076452\\
};
\end{axis}
\end{tikzpicture}

Unfortunately, the output of the same Latex file is not good:

b

Only the subplot on the right is visible. I note that the tikz file still contains both plots. I also note that the same problem exist even using the \input{aaa.tikz} command.