- Control over the spacing between the plots and around the edges of the layout
- An option for a shared title at the top of the layout
- Options for shared x- and y-axis labels
- An option to control whether the tiling has a fixed size or variable size that can reflow
How can I insert a title over a group of subplots?
조회 수: 8,362(최근 30일)
MathWorks Support Team 2022년 8월 1일
편집: MathWorks Support Team 2022년 8월 3일
Starting in R2019b, you can use the tiledlayout and nexttile functions to create a configurable tiling of plots. The configuration options include:
An example of 'tiledlayout' used to create a 2x2 group of subplots is written below:
tcl = tiledlayout(2,2);
title(tcl,'Subplot Grid Title')
For more information, see Combine Multiple Plots.
Starting in R2018b, you can use the 'sgtitle' function to add a title to a group of subplots. For example:
sgtitle('Subplot Grid Title')
For more information on the 'sgtitle' function, see https://www.mathworks.com/help/matlab/ref/sgtitle.html.
In previous releases (before R2018b), you can create the appearance of a super title by creating the subplots in a panel and adding a title to the panel. For an example, see:
jcjaimes 2016년 12월 15일
Suptitle does the job
suptitle('I am a super title')
Paul Huxel 2018년 10월 9일
Jonathan Beard 2017년 5월 9일
Here's a solution that doesn't require additional functions.
subplot(2, 1, 1);
subplot(2, 1, 2);
currentFigure = gcf;
Bradley 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.
Eric Sargent 2020년 12월 9일
편집: Eric Sargent 2020년 12월 9일
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:
Alternatively, starting in R2018b, the sgtitle function will add a title over a group of subplots.
tl = tiledlayout(3,3);
for i = 1:9
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.
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.