MATLAB Answers

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

6,423 ビュー (過去 30 日間)
I would like to place a title over a group of subplots. How can I do this?

採用された回答

MathWorks Support Team
MathWorks Support Team 2020 年 1 月 23 日
編集済み: MathWorks Support Team 2020 年 1 月 23 日
As of MATLAB R2018b, the sgtitle 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 件のコメント

表示 4 件の古いコメント
Walter Roberson
Walter Roberson 2018 年 6 月 18 日
suptitle() is part of the Bioinformatics toolbox.
Joakim Wang Erlandsson
Joakim Wang Erlandsson 2018 年 10 月 16 日
>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...
madhan ravi
madhan ravi 2018 年 10 月 16 日
There’s a new feature in 2018b which makes it possible

Sign in to comment.

その他の回答 (7 件)

jcjaimes
jcjaimes 2016 年 12 月 15 日
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 件のコメント

Chirag Parekh
Chirag Parekh 2016 年 12 月 30 日
@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.
Hannah West
Hannah West 2018 年 1 月 25 日
This worked for me.
Thanks!
Abdoulaye SAADOU YAYE
Abdoulaye SAADOU YAYE 2018 年 8 月 7 日
Worked pretty well. Thanks!

Sign in to comment.


Paul Huxel
Paul Huxel 2018 年 10 月 9 日
Starting in R2018b, you can use sgtitle to add a title to subplot grids:

  3 件のコメント

Raviteja Vangara
Raviteja Vangara 2018 年 10 月 9 日
Cool!!! Thank you....
Eduardo Rey
Eduardo Rey 2020 年 2 月 26 日
This actually works, nice!
LEONG SING YEW
LEONG SING YEW 2020 年 3 月 8 日
Thanks :D

Sign in to comment.


Jonathan Beard
Jonathan Beard 2017 年 5 月 9 日
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');

  7 件のコメント

表示 4 件の古いコメント
Jeffrey Roth
Jeffrey Roth 2019 年 2 月 19 日
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
Shyam Gouri Suresh 2019 年 9 月 3 日
PROSANJEET SARKAR
PROSANJEET SARKAR 2020 年 3 月 27 日
sgtitile() function you cane used it provide in 2018 verison of matlab

Sign in to comment.


Anders Bertelsen
Anders Bertelsen 2017 年 9 月 13 日
編集済み: Stephen Cobeldick 2017 年 9 月 13 日
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')

  2 件のコメント

Khan Bahadar Khan
Khan Bahadar Khan 2019 年 5 月 10 日
Untitled.png
how can i display images in MATLAB like this.
Walter Roberson
Walter Roberson 2019 年 5 月 11 日
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

Sign in to comment.


Dan
Dan 2017 年 10 月 31 日
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 件のコメント

Sign in to comment.


Brad Stiritz
Brad Stiritz 2018 年 9 月 9 日
>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 件のコメント

ANKUR KUMAR
ANKUR KUMAR 2018 年 9 月 10 日
There is a function suptitle which may does our work. It puts perfectly the title over all subplots.
Cris LaPierre
Cris LaPierre 2018 年 10 月 25 日
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.


JB
JB 2019 年 7 月 4 日
A great big thank you to the writer of mtit! That worked great for me, being someone who is between 2018 and the version I originally wrote my code in where my title for the subplot was centered without having to do anything extra.

  0 件のコメント

Sign in to comment.


Translated by