Code covered by the BSD License  

Highlights from
suplabel

4.0

4.0 | 21 ratings Rate this file 227 Downloads (last 30 days) File Size: 2.54 KB File ID: #7772
image thumbnail

suplabel

by Ben Barrowes

 

03 Jun 2005 (Updated 23 Mar 2010)

Places text as a title, xlabel, or ylabel on a group of subplots.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

PLaces text as a title, xlabel, or ylabel on a group of subplots. Returns a handle to the label and a handle to the axis.

[ax,h]=suplabel(text,whichLabel,supAxes)

returns handles to both the axis and the label.

ax=suplabel(text,whichLabel,supAxes)

returns a handle to the axis only. suplabel(text) with one input argument assumes whichLabel='x'

whichLabel is any of 'x', 'y', or 't', specifying whether the text is to be the xlable, ylabel, or title respectively.
 
supAxes is an optional argument specifying the Position of the "super" axes surrounding the subplots. supAxes defaults to [.075 .075 .85 .85] specify supAxes if labels get chopped or overlay subplots

EXAMPLE:
   subplot(2,2,1);ylabel('ylabel1');title('title1')
   subplot(2,2,2);ylabel('ylabel2');title('title2')
   subplot(2,2,3);ylabel('ylabel3');xlabel('xlabel3')
   subplot(2,2,4);ylabel('ylabel4');xlabel('xlabel4')
   [ax,h1]=suplabel('super X label');
   [ax,h2]=suplabel('super Y label','y');
   [ax,h3]=suplabel('super Title' ,'t');
   set(h3,'FontSize',30)
 
  SEE ALSO: text, title, xlabel, ylabel, zlabel, subplot,
            suptitle (Matlab Central)

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 (34)
06 Jun 2005 urs (us) schwarz

1) nice little helper; 2) it would be more convenient if supaxes would default to the outer boundaries of all axes on the canvas if it is not defined by the user (see mtit on the FEX); 3) supaxes' default values do not correspond to those shown in the help section

07 Aug 2006 jon erickson

Thank you--just what I was looking for! very easy to use. Just to follow up on comment 3) above, the default values are [0.08 0.08 0.84 0.84], not a major change.

19 Aug 2007 him s

nopes..not working

11 Oct 2007 Pablo Velarde

Excellent!

31 Mar 2008 pippo baudo  
19 Apr 2008 Chris Addison

Exactly what I was looking for! Thanks for this.

23 Apr 2008 Tom Van Grootel

Axes below the "Ghost" axes made by SUPLABEL are not editable (zoom, scale, rotate). Hint to improve this: 'HitTest' set to 'Off', but this still did not solve it.

16 Jun 2008 Pablo Pablo

I can not rotate an image when I use this function.

07 Aug 2008 Pierrick Mialle  
12 Aug 2008 Jake Munster

Useful tool, but as Tom Van Grotel said, I can't zoom in on the subplots! Setting 'HitTest' to 'Off' did not work =(

24 Feb 2009 Henry

Good tool, but like all other comments, I cannot zoom/rotate the image afterwards.

07 Aug 2009 omzaz  
07 Aug 2009 omzaz

potentially useful for me, but not until zoom/rotate issue is fixed.

03 Sep 2009 Scott Otterson

A quick solution to a common problem. Zooming would be nice -- I haven't checked the underpinnings, but if anyone is interested in taking a look

http://www.mathworks.com/matlabcentral/fileexchange/19314

decorates plots with extra labels and survives the zoom button

23 Sep 2009 Joe McGlinchy

GREAT! works perfect thanks

09 Nov 2009 sophie neve

I have aproblem with it : if I only do 4 subplot out of 6, for example 1,2,4,5 and not 3 and 6, the title is not centered any more.... sad :(

09 Nov 2009 sophie neve

I have seen another think that is sad : no greek letter is allowed
Example :
suplabel('log_{10} (Re \epsilon *)','y');

does not write the epsilon, right?

11 Dec 2009 Lars

Quite useful and simple to use. You might consider to change the argument checking to allow for cell strings (multi-line) labels:

if ~(ischar(text) || (iscell(text) && all(cellfun(@ischar,text))))
  error('text must be a string or a cell string')
end
if ~ischar(whichLabel)
  error('whichLabel must be a string')
end

04 Feb 2010 Daniel Golden

The problem with zooming is that suplabel places its axis on top of all other axes in the figure. You can fix this by adding the following lines under the
ax=axes('Units','Normal','Position',supAxes,'Visible','off');
line:

ch = get(get(ax, 'parent'), 'children');
set(get(ax, 'parent'), 'children', [ch(2:end); ch(1)]);

This moves the "suplabel" axis to the bottom of the figures' axes list and allows you to mess with the original axes on the figure.

11 Feb 2010 Patrick Tai  
11 Feb 2010 Patrick Tai

I want to have a super-legend.
When the subplots are all multi-lined with the same grouping scheme, their legends will be the same. Putting a legend in each will be too busy and take too much space.
Is there a way to put the common legend outside the plot matrix?

25 Feb 2010 Jason

Is there a way to have a second "super Y label" that corresponds to subplots 2 and 4 of the example figure?

Thanks.

22 May 2010 GERMÁN

when I want three subttulos the super title. How should it be?

L1 = "Energy spectrum function E = f (FFT (\ kappa) ^ 2) ';
L2 = ['height'];
L3 = ['Regression']
 [AX4, h3] = suplabel ([L1, L2, L3], 't');
thanks!!

22 May 2010 GERMÁN

when I want three titles in the super title. How should it be?

 L1 = "Energy spectrum function E = f (FFT (\ kappa) ^ 2) ';
L2 = ['height'];
L3 = ['Regression']
 [AX4, h3] = suplabel ([L1, L2, L3], 't');

   
thanks

01 Jun 2010 Geo

A very useful script!!! Thank you a lot!

04 Sep 2010 Gemma

Thank you very much.. i know have some awesomely titled plots :)

14 Oct 2010 Anthony Hopf

Can't seem to get multi-line to work... posted in NewsReader

14 Oct 2010 Anthony Hopf

Using Lars advice I can use multi-line and latex!! Nice function

12 Nov 2010 Christopher

Has anyone given thought to vectorizing or otherwise speeding up suplabel? I have figures with many subplots (of histograms), eg., subplot(6,8,i); and using suplabel to create the x- and y-labels changes the figure creation time from 5 seconds to 30 seconds.

12 Nov 2010 Christopher

And I have some code that changes that figure creation time using suplabel from 30 seconds back down to 5.2 seconds. Apply the following to suplabel, replacing the loop through ah (lines 74 to 82) with:
%%%%%
AH=get(ah);
ii=find(strcmp({AH(:).Visible}.','on'));
thisPos=reshape([AH(ii).Position],4,length(ii)).';
leftMin=min(thisPos(:,1));
bottomMin=min(thisPos(:,2));
leftMax=max(thisPos(:,1)+thisPos(:,3));
bottomMax=max(thisPos(:,2)+thisPos(:,4));
%%%%%
 and replacing line 110, kudos to Daniel Golden for his suggestion above, with
%%%%%
ch = get(get(ax, 'parent'), 'children');
set(get(ax, 'parent'), 'children', [ch(2:end); ch(1)]);
%%%%%
Now (almost) all multi-handle axis operations are vectorized.

I do not know how to do it yet, but I will try to put up a unified diff patch if I can figure how to attach a file.

02 Dec 2010 omzaz

Does not work with plotyy.....it removes the 2nd axis plot

26 Jan 2011 K R

This is fantastic - a huge time saver and so easy to use. Thank you!

24 Jun 2011 Jeff Evans  
13 Sep 2011 Erica B

Anyway to get the super label to not be squished at the top of the figure window, and closer to the subplots? Top of super title is nearly cut-off, while there is a chunk of space between the super title and the subplots.

I tried
[ax,h1]=suplabel([' ',' ','Title'],'t');
to put some empty lines above the title, but it's still squished at the top of the window...

Please login to add a comment or rating.
Updates
07 Jun 2005

Updated default values.

23 Jun 2005

Default behavior now detects existing axes.

03 Sep 2009

added capability for right side y-label

23 Mar 2010

Modified to restore visible axes on exit. Now zoomable, etc. on exit.

23 Mar 2010

Restores visible axes at exit. Now zoomable, etc. at exit.

Tag Activity for this File
Tag Applied By Date/Time
annotation Ben Barrowes 22 Oct 2008 07:49:49
customization Ben Barrowes 22 Oct 2008 07:49:49
super Ben Barrowes 22 Oct 2008 07:49:49
label Ben Barrowes 22 Oct 2008 07:49:49
title Ben Barrowes 22 Oct 2008 07:49:49
xlabel Ben Barrowes 22 Oct 2008 07:49:49
ylabel Ben Barrowes 22 Oct 2008 07:49:49
subplot Ben Barrowes 22 Oct 2008 07:49:49
group Ben Barrowes 22 Oct 2008 07:49:49
super Greg 23 Nov 2009 03:58:04
super Sander Aerts 30 Apr 2010 07:39:45
annotation Jose Ercolino 09 Aug 2010 20:29:55
label Jose Ercolino 09 Aug 2010 20:29:58
subplot Jose Ercolino 09 Aug 2010 20:30:00
title Jose Ercolino 09 Aug 2010 20:30:03
label Miki 17 Dec 2010 10:59:09
super David 23 Jun 2011 14:16:46
title XUEFEI 20 Jan 2012 06:36:47
super XUEFEI 20 Jan 2012 06:37:54

Contact us at files@mathworks.com