MATLAB Answers

How do I add a title to each subplot?

조회 수: 3,670(최근 30일)
marie
marie 2013년 3월 13일
편집: MathWorks Support Team 2021년 3월 23일
I have the following codes
delta=[-2*pi:0.063:2*pi];
y=sin(delta);
subplot(3,2,1)
plot(y)
y=cos(delta);
subplot(3,2,2)
plot(y)
title(sin(delta))
My question is how do i put the title for each graph and labels? i tried to to do title(sin(delta)) but it doesn't show

채택된 답변

Image Analyst
Image Analyst 2013년 3월 13일
편집: MathWorks Support Team 2021년 3월 23일
Starting in R2019b, you can use the tiledlayout and nexttile functions to create a configurable tiling of plots. The configuration options include:
  • 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
For more information, see Combine Multiple Plots.
For R2019a and before, put the title commands after the plot and before the next subplot. Specify the title as a character vector or string scalar.
delta=[-2*pi:0.063:2*pi];
y=sin(delta);
subplot(3,2,1)
plot(y)
title('sin(delta)')
y=cos(delta);
subplot(3,2,2)
plot(y)
title('cos(delta)')

추가 답변(2개)

Chad Greene
Chad Greene 2016년 4월 28일
For subplots I often prefer to use ntitle rather than title. The difference is ntitle keeps the text closer to the data, whereas title places the text high above the axes, where it may appear to be an xlabel for to the plot above.

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 13일
title('sin(delta)')
  댓글 수: 2
Chad Greene
Chad Greene 2019년 4월 5일
Or this, which is shorter, simpler, and just as effective :-)
title sin(delta)

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by