Code covered by the BSD License  

Highlights from

5.0 | 2 ratings Rate this file 25 Downloads (last 30 days) File Size: 3.48 KB File ID: #24510 Version: 1.0




Shrinks the length of the legend lines.

| Watch this File

File Information

legendshrink reduces the amount of horizontal space taken up by a figure legend by reducing the length of lines. (Best results when the legend box is off.)

This is important for small plots because the size of the lines is
constant irrespective of the physical size of the figure. Only works
for vertical legends, for now.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
04 May 2014 Adam Danz

Adam Danz (view profile)

Thanks for the code. I have a vertical legend in the upper right corner with two elements within the legend. The code is shrinking one of the elements as described but upon the second loop, I get the following error:

Error using hg.hggroup/get
The name 'XData' is not an accessible property for an instance of class 'hggroup'.
Error in legendshrink (line 114)
linepos = get(cch(ii),'XData');

Comment only
03 Apr 2014 Morteza

Excellent. Thanks for the script.

31 Oct 2013 Philip Ohnewein

Works nicely (when used with legend box off), but unfortunately it does not work when printing a figure. With print preview, the legend is set back to the way it looks without legendshrink.

Comment only
25 Apr 2013 Leo Simon

I'd prefer to leave the legend box on. Is there any way of shrinking the box as you shrink the lines?

Comment only
16 Dec 2009 Ross

Ross (view profile)

Excellent little script. Did exactly what I needed it to do for a small figure.

Contact us