- write the legend without the LaTeX
- get the position of the legend
- delete that legend
- write the real legend
- set the position of the real legend to the value you got
Size of legend box
51 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I have a problem with the size of the box around the legend in a plot. I am using LaTeX commands in the legend, which Matlab does not know. This is not a problem, because I am exporting the figure with mlf2pdf and the code will interpreted properly. But, Matlab sets the sizes of the box around the legend including the unknown code. The result is, that in the PDF file at the right side of the legend box is a big white space. Trying to resize the box (that's where the factor 0.8 is) results in moving it.
The following code shows an example:
clf;
hfig = figure(1) ;
set(hfig,'units','centimeters') ;
x = linspace(0,1,101) ;
f = sin(2*pi*x) ;
plot(x,f) ;
hleg = legend('$N = 1 \dotsc 101$','Location','NorthEast') ;
fig_pos = get(hfig,'position') ;
set(hfig,'position',[fig_pos(1:2),10,10]) ;
leg_pos = get(hleg,'position') ;
set(hleg,'position'[leg_pos(1),leg_pos(2),...
leg_pos(3)*0.8,leg_pos(4)]) ;
FileName = '~/dummy' ;
unix(sprintf('rm %s.*',FileName)) ;
mlf2pdf(1,FileName,'amssymb')
Would be cool if someone have an idea.
Thanks, Ralf
0 comentarios
Respuestas (1)
the cyclist
el 5 de Ag. de 2011
This code will move the legend box to the right, by the same amount you trimmed the width. Will that work for you?
set(hleg,'position',[leg_pos(1)+0.2*leg_pos(3),leg_pos(2),...
leg_pos(3)*0.8,leg_pos(4)]) ;
The other strategy I thought of is very kludgy. You could
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!