[Tex/LaTex] matlab2tikz font size

fontsizematlab2tikz

I Latex, how can I change/reduce the font size on a Matlab figure created by using matlab2tikz?

I would like to reduce the font size on the axis numbers, labels, title, legend, etc.

It does not need to be in latex, when using input function, it is also okay if I can use some commands in the Matlab script creating the tikz figure.

E.g., I would like to reduce font size: "Title", "x-label", "y-label", "legend", and the numbers on the x and y axis.

plot(1:4)
xlabel('x-label')
ylabel('y-label')
title('Title')
label('A line')

matlab2tikz('Test.tikz', ...
   'height','\figureheight','width','\figurewidth', ...
   'parseStringsAsMath',true);`

I Latex:

\begin{figure}
\centering
\setlength\figureheight{2cm}
\setlength\figurewidth{3cm}
\input{Test}
\end{figure}

Hope you guys can help me. Thank you in advance.
Best, Peter

UPDATE:

For some reason I cannot change ticklabel, either font size or color.

Matlab code:

figure;subplot(211);plot(1:10);ylabel('stuff');subplot(212);plot((1:10)*2);
ylabel('stuff');xlabel('other stuff');

matlab2tikz('test.tikz', ...
    'height','\figureheight','width','\figurewidth', ...
      'extraaxisoptions',['xlabel style={font={\color{blue}}},'...
                          'ylabel style={font=\tiny},',...
                          'ticklabel style={font=\color{red}}']);

When I include the picture in Latex, the ticklabels does not change color, while xlabel and ylabel do change as desired. Can some one tell me why?

I would like to decrease font size for both all labels (label and ticks on x- and y-axis)

Below is the content of 'test.tikz' file

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

\begin{axis}[%
width=0.95092\figurewidth,
height=0.418605\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=1,
xmax=10,
xlabel={other stuff},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=0,
ymax=20,
ylabel={stuff},
xlabel style={font={\color{blue}}},ylabel style={font=\tiny},ticklabel style={font=\color{red}}
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{%
1   2\\
2   4\\
3   6\\
4   8\\
5   10\\
6   12\\
7   14\\
8   16\\
9   18\\
10  20\\
};
\end{axis}

\begin{axis}[%
width=0.95092\figurewidth,
height=0.418605\figureheight,
at={(0\figurewidth,0.581395\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=1,
xmax=10,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=0,
ymax=10,
ylabel={stuff},
xlabel style={font={\color{blue}}},ylabel style={font=\tiny},ticklabel style={font=\color{red}}
]
\addplot [color=blue,solid,forget plot]
  table[row sep=crcr]{%
1   1\\
2   2\\
3   3\\
4   4\\
5   5\\
6   6\\
7   7\\
8   8\\
9   9\\
10  10\\
};
\end{axis}
\end{tikzpicture}%

Best Answer

pgfplots sets up a bunch of styles that determine how axis labels, titles, ticklabels etc. look. These can be redefined by adding options to the optional argument of the axis environment. For example, to change the size of the legend to \tiny, add legend style={font=\tiny}.

matlab2tikz allows you to append options to the axis with the extraAxisOptions parameter, so you could do something like

plot(1:4)
xlabel('x-label')
ylabel('y-label')
title('Title')
legend('A line')

matlab2tikz('Test2.tikz', ...
   'height','\figureheight','width','\figurewidth', ...
   'parseStringsAsMath',true,...
   'extraaxisoptions',['title style={font=\Huge},'...
                       'xlabel style={font={\color{blue}\bfseries}},'...
                       'ylabel style={font=\tiny},',...
                       'legend style={font=\scshape},',...
                       'ticklabel style={font=\color{red}}']);

to get the (rather silly) result

enter image description here

Another option is to use one of the predefined styles small, footnotesize or tiny, which is used as e.g.

\begin{axis}[tiny,
             ... %any other axis options

Note that these also modify the width and height of the plot, as well some other settings, so if added to the end of the options, as they would be with extraAxisOptions, they would override your width and height setting. Hence, to use these I think you need to edit the .tikz files.