Code covered by the BSD License  

Highlights from
LEGENDTITLE

3.1

3.1 | 10 ratings Rate this file 24 Downloads (last 30 days) File Size: 2.66 KB File ID: #4561

LEGENDTITLE

by Steve Simon

 

02 Mar 2004 (Updated 26 May 2006)

Add a title string inside a legend.

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
04 Mar 2004 Fahad Al Mahmood

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

05 Mar 2004 Jos x

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

01 Jun 2004 Andreas Hartmann

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

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.

07 Oct 2004 Holger Krause

Unfortunately this nice function doesn't work with R14.

29 Apr 2005 Michel Garcia

didn't work!

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! ;-)

14 Jun 2007 Romario Do Nacimento

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

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

08 Sep 2009 David DeVilbiss

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

02 Oct 2009 Ben Witvliet

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

08 Dec 2009 Cristian

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

08 Nov 2010 Kaare

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

Please login to add a comment or rating.
Updates
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.

26 May 2006

Update to work in R14 and later.

Tag Activity for this File
Tag Applied By Date/Time
annotation Steve Simon 22 Oct 2008 07:15:22
customization Steve Simon 22 Oct 2008 07:15:22
legend title Steve Simon 22 Oct 2008 07:15:22
title Steve Simon 22 Oct 2008 07:15:22
axes Steve Simon 22 Oct 2008 07:15:22
legend Steve Simon 22 Oct 2008 07:15:22
graphics Steve Simon 22 Oct 2008 07:15:22
plot annotation Steve Simon 22 Oct 2008 07:15:22
plot Steve Simon 22 Oct 2008 07:15:22
legend Chau 25 Mar 2009 19:44:47
annotation Jose Ercolino 23 Mar 2011 22:42:00
axes Jose Ercolino 23 Mar 2011 22:42:03
graphics Jose Ercolino 23 Mar 2011 22:42:06
legend Jose Ercolino 23 Mar 2011 22:42:11
title Jose Ercolino 23 Mar 2011 22:42:28
annotation Gustavo 13 Jun 2011 15:30:03

Contact us at files@mathworks.com