How do I move the legend box closer to the plot-edge? 2014b puts the legend box too far into the plot.
14 views (last 30 days)
Show older comments
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 Comments
Answers (7)
the cyclist
on 9 Oct 2014
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
on 9 Oct 2014
Edited: Doug Hull
on 9 Oct 2014
I ran this code in both versions. Am I missing something? I would say they are functionally equivalent.
2 Comments
the cyclist
on 9 Oct 2014
One man's "functionally equivalent" is another man's "clear difference", I guess.
Doug Hull
on 9 Oct 2014
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
on 9 Oct 2014
Edited: Doug Hull
on 9 Oct 2014
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 Comments
Doug Hull
on 9 Oct 2014
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 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!