
How do I change properties of a legend in a figure in 2016b? All code I have tries results in no change
8 views (last 30 days)
Show older comments
I am trying to make 3 changes to my plot: 1) change the font size and font to Times New Roman 12 for the axes labels and for the legend labels, 2) change the font of the numbers on the axes labels to Times New Roman, 3) in the legend, make the line thickness increase while still showing the plotting symbol (in this case '+') because I have lots of lines and colors and want to make the colors easier to see for each line.
I can successfully change the axes lables font and font size with:
set(findall(gcf,'-property','FontSize'),'FontSize',12)
set(findall(gcf,'-property','FontName'),'FontName','Times New Roman')
however, this does not change the font or font size in the legend. I have tried various other options, as seen below, but none of them have worked:
set(0,'defaultLegendFontName','Times New Roman')
set(findall(gcf,'type','text'),'FontName','Times New Roman')
set(gca,'FontName','Times New Roman')
I have also tried the following:
leg=legend({'A','B','C','D','E','F','G','H'},'FontSize',48,'Location','northwest');
ch=get(leg,'Children');
for i=1:length(ch)
set(ch(i),'FontName','Times New Roman')
end
and this:
[~,hObj]=legend({'A','B','C','D','E','F','G','H'},'FontSize',14,'FontName','Times New Roman','Location','northwest');
hL=findobj(hObj,'type','line');
set(hL,'linewidth',5)
hF=findobj(hObj,'type','font');
set(hF,'FontName','Times New Roman')
leg=findobj(gcf,'Tag','legend');
set(leg,'FontName','Times New Roman')
set(findall(gca,'Type','Line'),'LineWidth',2)
however, none of these work to change the FontName, FontSize in the legend, or of the numbers on the axes, or to make the lines in the legend thicker to be able to see the color more clearly, while still having the '+' symbol used to plot.
Any suggestions would be much appreciated. (using Matlab 2016b)
1 Comment
Jannik
on 6 Nov 2017
hey i tryed
[~,hObj]=legend({'A','B','C','D','E','F','G','H'},'FontSize',14,'FontName','Times New Roman','Location','northwest');
hL=findobj(hObj,'type','line');
set(hL,'linewidth',5)
hF=findobj(hObj,'type','font');
set(hF,'FontName','Times New Roman')
leg=findobj(gcf,'Tag','legend');
set(leg,'FontName','Times New Roman')
set(findall(gca,'Type','Line'),'LineWidth',2)
works absolutely fine for me.. result: i have the same Version of matlab so i dont get the Problem :/

Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!