Default Text Size in Legends
Ältere Kommentare anzeigen
Hi everybody, My problem is the following.
I need to change the default size of the text displayed in the figure legends, setting it, for example, to 22. Therefore I have inserted in the startup file, where I define my default graphics preferences, the following command:
set(0,'DefaultLegendFontSize',22);
Curiosly, I didn't get any error, but the command does not work, that is, Matlab continues to produce legend whose labels have the same font size (26) that I have set for x/y-axis label using set(0,'DefaultTextFontSize',26);
I have read that the command set(0,'DefaultTextFontSize',26); should set the font size also of legend. For this reason I have written in my startup file the set(0,'DefaultLegendFontSize',22); AFTER set(0,'DefaultTextFontSize',26); hoping in this way to 're-write' for labels the general option set for text.
A strange thing is that set(0,'DefaultLegendFontSize',22);, which does not work, does not produce any error message..
Does anyone know how to change the default size of text in labels? I know how to change it once created each figure using for example
h_legend=legend('a','b'); set(h_legend,'FontSize',22);
but I would prefer to change it by default
Thanks in advance, Giovanni Betti Beneventi
1 Kommentar
Sanket Diwale
am 10 Feb. 2016
Matlab 2015b Help on Legend Properties says the following about legend text size being scaled according to the axes size:
"Font size, specified as a scalar value greater than zero in point units. The default value is 9 points. If you change the axes font size, then MATLAB automatically sets the legend font size to 90% of the axes font size. If you manually set the legend font size, then changing the axes font size does not affect the legend."
I am guessing this is somehow preventing the default legend text size to change even though the property can be accessed and changed through set(0,'DefaultLegendFontSize',22);
Mathworks needs to clarify how this default property can be changed such that it works.
Akzeptierte Antwort
Weitere Antworten (1)
Sean de Wolski
am 26 Apr. 2012
A legend is just a form of an axes, i.e:
peaks;
h = legend('peaks');
get(h,'type')
And thus you would need to set the axes' fontsize. This might have adverse affects elsewhere.
I would take another approach and write your own wrapper for legend that manually sets the fontsize. E.g. something along the lines of:
function h = mylegend(varargin)
%Wrapper for legend that will set it to size 22.
h = legend(varargin{:})
set(h,'fontsize',22)
1 Kommentar
Chibuzo Nnonyelu
am 25 Mär. 2016
get(legend, 'type')
returns
legend
The defaultLegendFontSize property can not be changed. It is always 90% of the AxesFontSize.
Kategorien
Mehr zu Legend finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
