6.486 views (last 30 days)

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

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

Paul Huxel
on 9 Oct 2018

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

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

Jeffrey Roth
on 19 Feb 2019

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

Shyam Gouri Suresh
on 3 Sep 2019

PROSANJEET SARKAR
on 27 Mar 2020

sgtitile() function you cane used it provide in 2018 verison of matlab

Anders Bertelsen
on 13 Sep 2017

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

Walter Roberson
on 11 May 2019

There are multiple possibilities. The ones I can think of off-hand include:

- create an axes for each of the images, and an axes for each of the titles above and each of the titles to the side. Using subplot() for this purpose is not great, as you do not want the axes to all be the same size. Each axes could been panned, scrolled, zoomed, or data cursored individiually.
- create the top left axes with room for title and ylabel and an image. Create 3 axes below that with room for ylabel and an image. Create top right axes with room for title and image. Create three axes below that with room for an image. Using subplot() for this purpose is not great, as you do not want the axes to all be the same size. Each axes could been panned, scrolled, zoomed, or data cursored individiually.
- create a 4 x 2 array of axes the same size, all large enough to accomodate title and ylabel. Then carefully "tuck" the axes in so only the wanted parts show. Using subplot() for this might not be bad, but you will need to move the axes carefully. Each axes could been panned, scrolled, zoomed, or data cursored individiually.
- Use montage or similar to create a 4 x 2 image array and display it in an axes that you put appropriate text labels on. It would not be possible to scroll or pan or zoom the images individually, and you would need extra work to data cursor them individually. On the other hand, a single movable graphics cursor covering multiple images would become easier than in the other approaches mentioned above

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.

ANKUR KUMAR
on 10 Sep 2018

There is a function suptitle which may does our work. It puts perfectly the title over all subplots.

Cris LaPierre
on 25 Oct 2018

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.

Dan
on 31 Oct 2017

JB
on 4 Jul 2019

Gouater Loic
on 6 Oct 2020

This video clearly explains that https://www.youtube.com/watch?v=VX-vPvcqoSw

Eric Sargent
on 9 Dec 2020

Edited: Eric Sargent
on 9 Dec 2020

Starting in R2019b, you can also use tiledlayout and nexttile instead of subplot, which has shared titles and labels. You can use the title, xlabel, and ylabel commands directly with tiledlayouts:

tl = tiledlayout(3,3);

for i = 1:9

nexttile(tl)

plot(rand(5,1));

end

title(tl,'Layout Title');

xlabel(tl,'Layout XLabel');

ylabel(tl,'Layout YLabel');

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 8 Comments

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_366341

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_366341

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_507127

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_507127

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_507129

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_507129

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_511314

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_511314

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_579876

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_579876

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_622955

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_622955

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_622958

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_622958

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_1195899

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/100459-how-can-i-insert-a-title-over-a-group-of-subplots#comment_1195899

Sign in to comment.