How do I change the font size in my legend?

조회 수: 4,535(최근 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
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
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;

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