- 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
36 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
the cyclist
2011-8-5
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!