Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improper legend box size in MATLAB?

Tags:

plot

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

  • The box size is too small. The words are out of box. I have tried set(lngd, 'interpreter','latex', 'fontsize', 10, [0 0 10 10]); to enlarge the box, but no luck.
  • I wish to move the legend box to the right bottom. I have tried set(lngd, 'southeast', 'interpreter','latex', 'fontsize', 10);, but no luck.

How may I fix these two problems?

like image 470
Sibbs Gambling Avatar asked Jan 01 '26 12:01

Sibbs Gambling


1 Answers

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.

like image 61
ysakamoto Avatar answered Jan 04 '26 22:01

ysakamoto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!