1

I have a problem with a tikz-picture concerning yticks. The plot contains two y-axes and it seems as if tikz cannot cope with that properly. I have already found this link (Aligning ticklabels in secondary y-axis in pgfplot), but texstudio has problems with compiling this solution.

The code is attached:

% 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.36078,0.58824}%
\definecolor{mycolor2}{rgb}{0.63137,0.69412,0.10196}%
%
\begin{tikzpicture}[font=\sffamily]

\begin{axis}[%
width=0.45\textwidth,
scale only axis,
xmin=0,
xmax=1,
xtick={  0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,   1},
xlabel={geregelte Machzahl $Ma_\textrm{N,Control}~\left\lbrack-\right\rbrack$},
xmajorgrids,
separate axis lines,
every outer y axis line/.append style={mycolor1},
every y tick label/.append style={font=\color{mycolor1}},
ymin=-50,
ymax=50,
ytick={-50, -25,   0,  25,  50},
%ylabel={Druckverlust $\triangle p_t~\left\lbrack\textrm{Pa}\right\rbrack$},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=mycolor1,solid,line width=1.5pt,forget plot]
  table[row sep=crcr]{%
0.05    0.577365307486616\\
0.1 -0.111634692511871\\
0.2 -1.53963469251175\\
0.3 -4.40663469252468\\
};
\addplot [color=mycolor1,solid,line width=1.0pt,forget plot]
 plot [error bars/.cd, y dir = both, y explicit]
 table[row sep=crcr, y error plus index=2, y error minus index=3]{%
0.05    0.577365307486616   2.02796281884957    2.02796281884957\\
0.1 -0.111634692511871  4.40885720562954    4.40885720562954\\
0.2 -1.53963469251175   10.948300604055 10.948300604055\\
0.3 -4.40663469252468   25.0851926876272    25.0851926876272\\
};
\end{axis}

\begin{axis}[%
width=0.45\textwidth,
scale only axis,
xmin=0,
xmax=1,
%xtick={  0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,   1},
every outer y axis line/.append style={mycolor2},
every y tick label/.append style={font=\color{mycolor2}},
ymin=-1,
ymax=1,
ytick pos=right,
ylabel near ticks,
ytick={  -1, -0.8, -0.6, -0.4, -0.2,    0,  0.2,  0.4,  0.6,  0.8,    1},
ylabel={Abweichung der Machzahl $\frac{Ma_\textrm{N,True}}{Ma_\textrm{N,Control}}-1~\left\lbrack\%\right\rbrack$},
axis x line*=bottom,
axis y line*=right
]
\addplot [color=mycolor2,dashdotted,line width=1.5pt,forget plot]
  table[row sep=crcr]{%
0.05    -0.0108565892090073\\
0.1 0.0541724835735558\\
0.2 0.0503289313137145\\
0.3 0.0224146746901743\\
};
\end{axis}
\end{tikzpicture}%
  • Hi, welcome. I don't know exactly what you tried, but if you're referring to the \widthof method, then you're affected by a change that was made between version 2.1 and 3 of TikZ. Use yticklabel style={text width=width("$-2.0$"),align=right} instead. – Torbjørn T. Apr 10 '17 at 17:51
  • Did my previous comment solve your problem? – Torbjørn T. Apr 15 '17 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.