File Exchange

image thumbnail


version (2.66 KB) by Steve Simon
Add a title string inside a legend.


Updated 01 Sep 2016

View License

LEGENDTITLE adds a title inside the legend axes.
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.


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

Comments and Ratings (15)


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).


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


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

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!


Updated license

Update to work in R14 and later.

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 Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Add a title to a legend