1

I am trying to change the font size of the tick labels, but they won't react to

\pgfplotsset{every tick label/.append style={font=\scriptsize}}

This is because I create the tikz-file automatically from Matlab. Hence, there are some settings for the tick labels, which somehow overwrite the font size somehow (although it is only the color). Now, can I globally change the tick label size without having to change the automatically produced tikz-file?

Also, is there a possibility to save space while aligning the plots and labels properly? Because right now, "ylabel 4" is a little bit out of the ordinary. When I use something like

\pgfplotsset{yticklabel style={text width=2.5em,align=center}}

the structure takes relatively much space. I know this is intended by the command, but maybe someone has an elegant solution to this?

Hope you understand my question, many thanks in advance!

My MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=newest}
\newlength\figureheight
\newlength\figurewidth

\newcommand{\inputTikz}[1]{
            \setlength\figureheight{0.35\textheight} 
            \setlength\figurewidth{\textwidth}
            \centering
            \resizebox{\textwidth}{!}{\input{#1}}}

\pgfplotsset{
  compat=newest,
    every axis/.append style={font=\footnotesize},
    every tick label/.append style={font=\scriptsize, yshift=0.5ex}
    }

\begin{document}

\begin{figure}
    \inputTikz{fig.tikz}
\end{figure}

\end{document}

The tikz-file "fig.tikz" is

\begin{tikzpicture}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0\figurewidth,0.542\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.071428579543637,
ymax=2.00000022722184,
ylabel={ylabel 1},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0 0\\
};

\end{axis}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0.503\figurewidth,0.542\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0227138669391646,
ymax=0.0227138674410331,
ylabel={ylabel 2},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0 0\\
};
\end{axis}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 1},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0500000006711102,
ymax=1.40000001879109,
ylabel={ylabel 3},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0   0\\
};

\end{axis}

\begin{axis}[%
width=0.39\figurewidth,
height=0.458\figureheight,
at={(0.503\figurewidth,0\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 2},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.264169253617191,
ymax=0.264169281884055,
ylabel={ylabel 4},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0   0\\
};
\end{axis}
\end{tikzpicture}%

Output

1

I don't completely understand what you want to achieve, but to answer your questions:

1) Use \pgfplotsset{every x tick label/.append style={font=\scriptsize}} instead.

2) You could put the y-axis ticks for the second and third plot on the right side instead and remove/decrease the horizontal separation of the plots. Use axis y line*=right in the options for these axes.

Depending on what your axes limits really looks like, it might or might not be a good idea to use groupplots instead of four axis environments.

Why do you use both a resizebox and width=\figurewidth when you input your figures? Imho, it would be better to just use:

\newcommand{\inputTikz}[1]{
            \setlength\figureheight{0.35\textheight} 
            \setlength\figurewidth{.9\textwidth} %For example .9
            \centering
            \input{#1}}

To avoid scaling of labels.

Here's an example of fig.tikz using groupplot instead: enter image description here

\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 2,horizontal sep=15pt}]
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.071428579543637,
ymax=2.00000022722184,
ylabel={ylabel 1},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0 0\\
};
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
separate axis lines,
axis y line*=right,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0227138669391646,
ymax=0.0227138674410331,
ylabel={ylabel 2},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0 0\\
};
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 1},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.0500000006711102,
ymax=1.40000001879109,
ylabel={ylabel 3},
ymajorgrids,
axis background/.style={fill=white},
legend style={at={(0.5,0.97)},anchor=north,legend columns=2,legend cell align=left,align=left,draw=black}
]
\addplot [color=blue,solid]
  table[row sep=crcr]{%
0   0\\
};
\nextgroupplot[width=0.39\figurewidth,
height=0.458\figureheight,
scale only axis,
axis y line*=right,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1.5,
xlabel={xlabel 2},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-0.264169253617191,
ymax=0.264169281884055,
ylabel={ylabel 4},
ymajorgrids,
axis background/.style={fill=white}
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0   0\\
};
\end{groupplot}
\end{tikzpicture}
  • I know that I've seen a solution that makes sure that all ylabels are equally far from the axes, can't remember where right now though. Label 4 is further from the axis compared to label 2 due to -0.2 having a greater width than -2. – Grimler Jun 25 '15 at 9:50
  • Thanks for your answer. I will try aligning the way you proposed. However, in your example the font size of the tick labels is still unchanged. Like I have written before, this is due to "every x tick label/.append style={font=\color{black}}" in the tikz file which overwrites the font size setting. I used the resizebox since without, the figure is shifted slightly to the right and overfull hboxes occur. – Hans Jun 25 '15 at 21:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.