MATLAB Answers

4

How do I change the font size in my legend?

Asked by MathWorks Support Team on 27 Jun 2009
Latest activity Edited by FastCar
on 21 Feb 2019
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');
LEG.FontSize = 10;

4 Answers

Answer by MathWorks Support Team on 12 Jun 2017
 Accepted Answer

You can change the font size for a MATLAB legend by setting the 'FontSize' property of the Legend object.
For example, plot four lines. Create a legend and assign the Legend object to the variable 'lgd'. Then, use dot notation to access the 'FontSize' property and set the value to 14 points.
plot(rand(4))
lgd = legend('One','Two','Three','Four');
lgd.FontSize = 14;
Alternatively, you can specify the 'FontSize' property using a name-value pair argument in the 'legend' command. When including name-value pair arguments, include the legend labels in a cell array. For example:
legend({'One','Two','Three','Four'},'FontSize',14)

  3 Comments

ali jebeli comments:
does not work
ali jebeli: which MATLAB version are you using?
I had the same problem, I am using version 2016b. The Legend box became bigger but the text rermains small.
What can I do?
edit: I needed to change manually, very frustrating. Unconvenient for such an expensive software.

Sign in to comment.


Answer by Mukesh Jadhav on 9 Oct 2016

Here you go :
h = legend('x','y','z');
set(h,'FontSize',12);

  1 Comment

Hi I am using 2015b. "h= legend('x','y','z'); set(h,'FontSize',12); worked really well and it is good when we need the axes' labels in bigger sizes However it took a very long time to proceed for such two simple lines! please advise

Sign in to comment.


Answer by odo22
on 1 Dec 2016

l = legend('1', '2', '3');
l.FontSize = 40;

  0 Comments

Sign in to comment.


Answer by Samson Msgna on 23 Mar 2018

How can we solve Error using CreateDatabase (line 22) Not enough input arguments.
Error using EigenfaceCore (line 20) Not enough input arguments.

  1 Comment

You need to pass the path of the directory containing the data to EigenfaceCore . See the example.m file for example.

Sign in to comment.