Sibbs Gambling
Sibbs Gambling

Reputation: 20355

Improper legend box size in MATLAB?

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

enter image description here

My two problems are

How may I fix these two problems?

Upvotes: 3

Views: 10950

Answers (3)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

  1. 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...)

  2. Use

    set(lgnd, 'location', 'southeast', ...);
    

Upvotes: 0

ysakamoto
ysakamoto

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

vbar
vbar

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

Related Questions