Reputation: 20355
I encountered a problem where the legend box is not automatically sized as the font size changes.
x = [1 4 6 8 0 2 4 7 8]
plot(x)
lngd = legend('Nov 5, 2010 09:00 - 09:01');
set(lngd, 'interpreter','latex', 'fontsize', 10);
generates the following graph
My two problems are
set(lngd, 'interpreter','latex', 'fontsize', 10, [0 0 10 10]);
to enlarge the box, but no luck.set(lngd, 'southeast', 'interpreter','latex', 'fontsize', 10);
, but no luck.How may I fix these two problems?
Upvotes: 3
Views: 10950
Reputation: 38032
I cannot reproduce the problem on MATLAB R2010a, R2010b or R2013a. What version do you have?
I have these defaults in my startup.m
:
set(0,...
'DefaultFigurePaperPositionMode', 'auto',...
'DefaultFigurePaperType' , 'A4',...
'DefaultFigurePaperUnits' , 'centimeters',...
'DefaultFigurePaperPosition', [3 3 8.4 10],...
'DefaultAxesFontsize' , 14,...
'DefaultTextColor' , 'black',...
'DefaultFigureRenderer' , 'openGl',...
'DefaultFigurePaperUnits' , 'centimeters',...
'DefaultFigurePaperPosition', [3 3 8.4 10],...
'DefaultAxesFontsize' , 14,...
'DefaultAxesFontname' , 'Times-Roman',...
'DefaultTextColor' , 'black');
Perhaps setting these changes things? (You'd be surprised how much some of these values affect sometimes...)
Use
set(lgnd, 'location', 'southeast', ...);
Upvotes: 0
Reputation: 2532
Is there any particular reason that you use 'interpreter', 'latex'
? It seems to mess with the boxing of the legend for some MATLAB. You can try to manually change the legend box position and size by setting the Position
variable.
x = [1 4 6 8 0 2 4 7 8]
plot(x)
lngd = legend('Nov 5, 2010 09:00 - 09:01');
set(lngd, 'fontsize', 10, 'interpreter','latex','Position', [0.55,0.15,0.35,0.08]);
The Position
vector is [left,bottom,width,height]
of the box in 0~1 range.
Upvotes: 3
Reputation: 81
x = [1 4 6 8 0 2 4 7 8]
plot(x)
lngd = legend('Nov 5, 2010 09:00 - 09:01');
set(lngd, 'Location', 'SouthEast');
set(lngd, 'interpreter','latex', 'fontsize', 30);
Try this, it works fine in my matlab
Upvotes: 2