How do I move the legend box closer to the plot-edge? 2014b puts the legend box too far into the plot.
28 次查看(过去 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
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
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!