View License

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

» Watch video

Highlights from

3.2 | 12 ratings Rate this file 6 Downloads (last 30 days) File Size: 2.66 KB File ID: #4561 Version:



Steve Simon (view profile)


02 Mar 2004 (Updated )

Add a title string inside a legend.

| Watch this File

File Information

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


This file inspired Add A Title To A Legend.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
05 Jun 2013 Peter

Peter (view profile)

19 Nov 2012 Felipe G. Nievinski

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

08 Nov 2010 Kaare

Kaare (view profile)

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

08 Dec 2009 Cristian

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

02 Oct 2009 Ben Witvliet

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

08 Sep 2009 David DeVilbiss

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

07 Jul 2008 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).

14 Jun 2007 Romario Do Nacimento

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

Comment only
20 Feb 2006 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! ;-)

29 Apr 2005 Michel Garcia

didn't work!

Comment only
07 Oct 2004 Holger Krause

Unfortunately this nice function doesn't work with R14.

Comment only
16 Jun 2004 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.

01 Jun 2004 Andreas Hartmann

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

05 Mar 2004 Jos x

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

04 Mar 2004 Fahad Al Mahmood

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

10 Mar 2004

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.

01 Sep 2016

Updated license

Contact us