Matlab用subplot画图,怎么加总标题

如题所述

你用Suptitle命令即可。下面是该命令的帮助文档。

suptitle('text') adds text to the top of the figure
  above all subplots (a "super title"). Use this function
  after all subplot commands.

下面是一个例子,注意,最好画完所有的子图后再用Suptitle,不然可能会出现和第一个子图的标题覆盖的情况。

clc;clear;close all
x = 0:0.01:4*pi;
y1 = cos(x);
y2 = sin(x);
figure(1)
subplot(2,1,1);
plot(x,y1);
title('cos(x)');
subplot(2,1,2);
plot(x,y2);
title('sin(x)');
suptitle('总标题')

下面是结果:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-16
用sgtitle('总标题')
这个语句要写在代码最后。比如:
figure()
subplot(2,1,1)
title('子标题1')
subplot(2,1,2)
title('子标题2')
sgtitle('总标题')
不知道是不是版本问题(我用的2018b), suptitle 会报错
相似回答