Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How do I change the font size in my legend?

Asked by MathWorks Support Team on 27 Jun 2009

When I attempt to change the font size of the text in a legend using the code shown below, the text becomes very large:

plot(rand(4))
AX=legend('One','Two','Three','Four');
LEG = findobj(AX,'type','text');
set(LEG,'FontSize',10)

0 Comments

MathWorks Support Team

Products

1 Answer

Answer by MathWorks Support Team on 27 Jun 2009
Accepted answer

In order to change the font size for a MATLAB legend, use the SET command to change the 'FontSize' property of the legend object, as in the example below.

plot(rand(4))
h_legend=legend('One','Two','Three','Four');
set(h_legend,'FontSize',14);

In MATLAB 7.1 (R14SP3), saving the figure to file after changing the Font Size on the legend may revert the font sizes to the original size. To work around this, the following option can be used from the Command Window to print the figure to a

file :

print -dbmp16m 'myfig.jpg'

0 Comments

MathWorks Support Team

Contact us