MATLAB Answers

3

How can I insert a title over a group of subplots?

I would like to place a title over a group of subplots. How can I do this?

7 Answers

Answer by MathWorks Support Team on 16 Nov 2018
Edited by MathWorks Support Team on 16 Nov 2018
 Accepted Answer

As of MATLAB R2018b, the sgtitile function will add a title over a group of subplots.
For earlier releases, check out the user-contributed mtit File Exchange submission for this functionality. If you have any questions, consult the author.
function gives you a similar functionality.

  7 Comments

suptitle() is part of the Bioinformatics toolbox.
>It is not possible to put a title over a group of subplots in MATLAB. >There is a user contributed function that places a title over a group of subplots
But good god just fix it then. Plotting in matlab is is joke (a sad one), always forced to resort to user provided workarounds...
There’s a new feature in 2018b which makes it possible

Sign in to comment.


Answer by jcjaimes
on 15 Dec 2016

Suptitle does the job
x=1:0.01:10;
subplot(2,2,1); plot(sin(x))
subplot(2,2,2); plot(cos(x))
subplot(2,2,3); plot(cos(x.^2))
subplot(2,2,4); plot(sin(x.^2))
suptitle('I am a super title')

  3 Comments

@jcjaimes Thanks!! 'suptitle' is not an inbuilt MATLAB function. It is part of a demo in Bioinformatics Toolbox, so it might not be available to all.

Sign in to comment.


Answer by Anders Bertelsen on 13 Sep 2017
Edited by Stephen Cobeldick on 13 Sep 2017

figure;
subplot(1, 2, 1);
plot(nan, nan);
subplot(1, 2, 2);
plot(nan, nan);
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 0.98,'Title')

  0 Comments

Sign in to comment.


Answer by Paul Huxel on 9 Oct 2018

Starting in R2018b, you can use sgtitle to add a title to subplot grids:

  1 Comment

Sign in to comment.


Answer by Jonathan Beard on 9 May 2017

Here's a solution that doesn't require additional functions.
figure;
subplot(2, 1, 1);
plot(nan, nan);
subplot(2, 1, 2);
plot(nan, nan);
currentFigure = gcf;
title(currentFigure.Children(end), 'blah');

  5 Comments

These methods only work if the subplots don't already have titles of there own, as it is just adding a title to the first subplot. The nice part about `suptitle` is that it puts an additional title above all the subplots.
I'm still looking for an easy solution without the Bioinformatics toolbox, as it's rather ridiculous to add 500 Mb to my install for this one function. Please consider making this standard.
https://www.mathworks.com/matlabcentral/answers/203703-is-it-possible-to-define-global-title-on-figures has a similar question with a slightly different way of putting a title over the subplots. Look at the answer by Brendan Hamm. Basically you create a new axes that takes up the whole plot, make it invisible, but make it's title visible.
A problem with sgtitle (at least on the linux distro) is that it seems to be persistent, meaning once you put an sgtitle into the figure you cannot get rid of it. How can one clear an sgtitle?
Not being able to clear it complicates making AVI videos using subplot.
I imagine there is a way to completetely delete the sgtitle using a handle to it (before writing the next one), but I haven't figured out yet how to do so. Can anyone provide guidance?
Thanks! Jeff

Sign in to comment.


Answer by Dan
on 31 Oct 2017

Thanks! This works great. I set did >set(h,'Position',[.5 1.05 .5]) to get place the supertitle above the titles of my subplots.

  0 Comments

Sign in to comment.


Answer by Brad Stiritz on 9 Sep 2018

>Answer by MathWorks Support Team on 26 Apr 2010
>It is not possible to put a title over a group of subplots in MATLAB..
With respect, this is not a helpful comment, as it's apparently not true. It is possible, just not with built-in core Matlab functionality. Most people will hopefully continue reading the thread, and learn about the workarounds. Still, it's not an encouraging or precise statement to begin the group discussion, IMHO.

  2 Comments

There is a function suptitle which may does our work. It puts perfectly the title over all subplots.
FYI: suptitle is only available to those who have the Bioinformatics toolbox, and then it was included in a demo file and is not an actual MathWorks maintained function.
However, as Paul Huxel points out, there is now (r2018b) a function in base MATLAB for this. It is called sgtitle.

Sign in to comment.