How do I move the legend box closer to the plot-edge? 2014b puts the legend box too far into the plot.
10 ビュー (過去 30 日間)
古いコメントを表示
Hi,
One of the big changes for me in version 2014b is that the legend box appears significantly further away from the plot edge, than it did in 2014a. Thus the legend box now obscures data it didn't just yesterday. :(
How can I decrease the buffer zone between the legend box and plot edge?
Yours, - Hrefna
0 件のコメント
回答 (7 件)
the cyclist
2014 年 10 月 9 日
You might want to post an example of what you are seeing. My legend positioning seems fine.
But here's an example where I plunk the legend directly in the middle:
% Some data
x = 0:pi/10:pi;
y = sin(x);
% Create figure
figure
plot(x,y,x,2*y)
hL = legend({'1','2'});
% Get current position (which I used to keep overall size the same)
currentLegendPosition = hL.Position;
% Define new position
newLegendPosition = [0.5 0.5 currentLegendPosition([3 4])];
% Set new position
hL.Position = newLegendPosition;
% % (You could also use this syntax)
% set(hL,'Position',newLegendPosition)
Doug Hull
2014 年 10 月 9 日
編集済み: Doug Hull
2014 年 10 月 9 日
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176019/image.png)
I ran this code in both versions. Am I missing something? I would say they are functionally equivalent.
2 件のコメント
the cyclist
2014 年 10 月 9 日
One man's "functionally equivalent" is another man's "clear difference", I guess.
Doug Hull
2014 年 10 月 9 日
Now we see why this is important. It is not possible to change the margin padding (either the external or internal), but it is easy to adjust the font size such that the legend gets a little smaller.
legend({'Blah1dat','Blah2dat','Blah3dat','Blah4dat','Blah5dat','Blah6dat'} ,'location', 'northwest','fontSize',8)
When I make the font one point smaller, the legend gets smaller and then it fits for your data.
Also, instead of specifying the location as Northwest, have you considered 'Best'
Doug Hull
2014 年 10 月 9 日
編集済み: Doug Hull
2014 年 10 月 9 日
I think I see why this looks different for both of us! My normal workflow is to use screenshots so I was posting what I saw on screen, you were posting what you print. I made my figure tall with just positioning on screen. Once I got it like I wanted, now to get a print, I do this.
set(gcf,'PaperPositionMode','auto');
print -djpeg LotsOfSubplots_LegendOnTop.jpg
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176022/image.jpeg)
This is more WYSIWYG. Try that.
0 件のコメント
Doug Hull
2014 年 10 月 9 日
You have control over the position of the figure, and thus its size. Everything that I did for this particular figure could be automatic. Depending on the particulars of your specific data and figures, you might be able to set the positions to be tall on screen then print as I did to get good effects.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!