Add a title to a group of 4 subplots centred at the top

조회 수: 3 (최근 30일)
HC98
HC98 2024년 8월 15일
답변: Star Strider 2024년 8월 15일
I have a group of subplots and want to add a title at the top, centre. How might one do this? Here is an MWE
subplot(2,2,1)
plot(peaks)
subplot(2,2,2)
plot(peaks)
subplot(2,2,3)
plot(peaks)
subplot(2,2,4)
plot(peaks)

답변 (2개)

Les Beckham
Les Beckham 2024년 8월 15일
I would suggest using tiledlayout instead of subplot. Then you attach the title to the tiledlayout rather than any of the individual plots.
tl = tiledlayout(2,2);
nexttile
plot(peaks)
nexttile
plot(peaks)
nexttile
plot(peaks)
nexttile
plot(peaks)
title(tl, 'Common title')

Star Strider
Star Strider 2024년 8월 15일
Use the sgtitle function (introduced in R2018b).
It works with subplot and tiledlayout figures.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by