File Exchange

image thumbnail

LEGENDTITLE

version 1.0.0.1 (2.66 KB) by

Add a title string inside a legend.

1 Download

Updated

View License

LEGENDTITLE adds a title inside the legend axes.
LEGENDTITLE(LEGH,TITLESTR) adds the title TITLESTR to the legend LEGH
LEGENDTITLE(TITLESTR) adds the title to the current legend in the current axes.
LEGENDTITLE(...,Param,Val) sets the specified properties for the text object.
H = LEGENDTITLE(...) returns the handle for the text object used to create the title string.
By default, the legend title uses the same font as the legend, but with a bold font weight.

Example:

plot(rand(10,5))
legh = legend('Random 1','Random 2','Random 3','Random 4','Random 5');
legendtitle(legh,'Random Data')

Comments and Ratings (15)

Peter

Peter (view profile)

It seems the problem can be avoided calling the saveas function instead of clicking Save As from the figure window's File menu (which internally calls hgexport).

Kaare

Kaare (view profile)

saving it to jpg, png or pdf messes it up, haven't tried any other formats.

Cristian

It does not work properly if you save the image as .eps.

Ben Witvliet

Just what I needed. Works fine in R2009a (64-bit version).

The function worked fine but will not allow the legend to be placed outside the axes.

Thierry Dalon

With R2008a it works perfectly.
It puts the title inside the box legend in bold.
(Default title property of legend put a title outside of the legend box).

Romario Do Nacimento

The function doesn't work in Matlab 14!!
Another option please!

valik pol

Didn't work: error in line 68: Function 'mrdivide' is not defined for values of class 'cell'.
I personally liked Jos' solution better, but this is supposed to put the title INSIDE the legend! And anyway, thanks for bringing up the issue! ;-)

Michel Garcia

didn't work!

Holger Krause

Unfortunately this nice function doesn't work with R14.

Chris Rodgers

Although this looks nice when first applied to a plot, it gets messed up as soon as I resize the plot... :-( This is more important than it might initially seem, since I use the exportfig.m tools to export / print my figures and this always involves a resize.

Andreas Hartmann

Nice function, and not redundant, it adds the title _inside_ the legend box

Jos x

Redundant! This does the job already:
>> h = legend(...) ;
>> set(get(h,'title'),'String','Legend Title')

Fahad Al Mahmood

Excellent function! Very easy to use ... thank you!

Updates

1.0.0.1

Updated license

Change description to indicate that title is inserted inside legend box, in response to review. The reviewer's code puts a title outside the legend axes.

MATLAB Release
MATLAB 7 (R14)
Acknowledgements

Inspired: Add a title to a legend

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video