5

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}%
  • 4
    make a super simple matlab plot (3-4 points) so that we can see what you mean by font size Is it the legend? Tick labels etc. Othewise please don't expect too much from us to make up an example. Probably you already have an example in your computer so why not making it obvious? – percusse Sep 14 '14 at 13:00
  • Thank you for your replay. I cannot see how an example will help illustrate what I look for. As I write I would like to reduce font size on the axis (numbers, ticks), labels, title, legend etc. Thus, I answer your question/concern about that which font I would like to reduce. – etyM Sep 14 '14 at 14:38
  • An example would save all of us to type an example try it on Matlab, export it to TikZ, compile that and see if it works and then try a solution. All this to help you which you already did on your own computer. – percusse Sep 14 '14 at 15:16
  • Hope above example help – etyM Sep 14 '14 at 15:27
  • @etyM Please add the contents of Test.tikz to your question and make the LaTeX code complete by adding \begin{document}, \end{document}, etc. In the Matlab code, did you mean legend('A line') instead of label('A line')? – mvkorpel Sep 15 '14 at 13:40
6

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.

  • Thank you very much for your complete answer! However, for some reason my ticklabel do not change color. I would like to change the font size, but nothing is chanced. Can you maybe give a hint on why this is the case? Are there something which may interfere with the ticklabel setting in Matlab? – etyM Dec 6 '14 at 13:49
  • @etyM I have no idea what your ticklabel settings in Matlab are, nor what code matlab2tikz produces, so it is very hard to give any hints. If you could edit your question to include minimal example codes (both from Matlab and matlab2tikz would be nice) I can take a look later. – Torbjørn T. Dec 6 '14 at 18:43
  • Alright, see update above. Hope it is as desired. – etyM Dec 6 '14 at 22:19
  • @etyM Not really, I meant the Matlab code that creates the plot in the first place, and the complete contents of the .tikz file. Your original data is unimportant, you can replace that with e.g. plot((1:24)*50). A minimal example (figure;subplot(211);plot(1:10);ylabel('stuff');subplot(212);plot((1:10)*2);ylabel('stuff');xlabel('other stuff');) followed by your matlab2tikz invocation works fine here, so I would need more information. I have version 0.4.7 of matlab2tikz and 1.11 of pgfplots. – Torbjørn T. Dec 8 '14 at 9:48
  • Torbjørn T: pfgplot is also 1.11, but I use matlab2tikz v0.6.0. See update above. Does this information help? Once again, thank you for your time/help! – etyM Dec 8 '14 at 13:32

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.