MATLAB Answers

How do I change the font size in my legend?

3,040 ビュー (過去 30 日間)
How do I change the font size of the labels in my legend? For example, how do I make the font size of the ‘One’, ‘Two’, ‘Three’, ‘Four’ labels bigger in my plot?
plot(rand(4))
lgd=legend('One','Two','Three','Four');

採用された回答

MathWorks Support Team
MathWorks Support Team 2020 年 9 月 2 日
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)

  4 件のコメント

表示 1 件の古いコメント
Walter Roberson
Walter Roberson 2017 年 9 月 20 日
ali jebeli: which MATLAB version are you using?
FastCar
FastCar 2019 年 2 月 21 日
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.
Jordan Fliss
Jordan Fliss 2020 年 12 月 4 日
This problem sounds like the one I am experiencing now. After I changed the setting I saved the figure as a .fig, closed the figure window, then loaded the figure again (by simply double clicking it). After the figure reloaded my legend font changes were implemented.

サインインしてコメントする。

その他の回答 (3 件)

Mukesh Jadhav
Mukesh Jadhav 2016 年 10 月 9 日
Here you go :
h = legend('x','y','z');
set(h,'FontSize',12);

  2 件のコメント

Tuyen Nguyen
Tuyen Nguyen 2018 年 2 月 5 日
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
Jamil Khan
Jamil Khan 2020 年 10 月 26 日
legend('x','y','z'),set(legend,'fontsize',12);
this works aswell, you dont have set the legend as an object

サインインしてコメントする。


odo22
odo22 2016 年 12 月 1 日
l = legend('1', '2', '3');
l.FontSize = 40;

  0 件のコメント

サインインしてコメントする。


Samson Msgna
Samson Msgna 2018 年 3 月 23 日
How can we solve Error using CreateDatabase (line 22) Not enough input arguments.
Error using EigenfaceCore (line 20) Not enough input arguments.

  1 件のコメント

Walter Roberson
Walter Roberson 2018 年 3 月 26 日
You need to pass the path of the directory containing the data to EigenfaceCore . See the example.m file for example.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by