一组子图的标题

时间:2015-11-08 12:30:53

标签: matlab label title figure subplot

有许多子图,每个子图都有自己的标题。如何在所有这些子图上添加标题? 我希望这个标题显示在顶部中心。

x = linspace(-5,5);

y1 = sin(x);
subplot(2,5,[1:2])
plot(x,y1)
title('y=sin(x)')

y2 = cos(x);
subplot(2,5,[3:4])
plot(x,y2)
title('y=cos(x)')

y3 = tan(x);
subplot(2,5,[5,10])
plot(x,y3)
title('y=tan(x)')

y4 = sin(2*x);
subplot(2,5,[6:7])
plot(x,y1)
title('y=sin(2x)')

y5 = cos(2*x);
subplot(2,5,[8:9])
plot(x,y2)
title('y=acos(2x)')

3 个答案:

答案 0 :(得分:7)

自Matlab 2018b起,新功能sgtitle向子图组添加标题,只需添加sgtitle('Subplot Title');。它不需要工具箱。

例如:

subplot(1,2,1)
plot(cos(0:40));
title('cos');

subplot(1,2,2)
plot(sin(0:40))
title('sin');

sgtitle('Trigo');

trigo

答案 1 :(得分:5)

我找到没有生物信息学工具箱的人最简单的方法是:

a = axes;
t = title('My title');
a.Visible = 'off';
t.Visible = 'on';

您正在做的是创建一组新的轴,默认情况下,这些轴覆盖整个图形,并在这些轴上创建标题。然后使轴变为不可见,并且对于再次可见的标题,这将被覆盖。

如果生成的标题与事物发生碰撞,请使用a.Position来移动轴。

是的,这不是基本功能的一部分是荒谬的,但是工具箱中隐藏着大量的单线或双线功能,人们可能会这么说;-)(看看你,range。)

答案 2 :(得分:4)

x = linspace(-5,5);

y1 = sin(x);
subplot(2,5,[1:2])
plot(x,y1)
title('y=sin(x)')

y2 = cos(x);
subplot(2,5,[3:4])
plot(x,y2)
title('y=cos(x)')

y3 = tan(x);
subplot(2,5,[5,10])
plot(x,y3)
title('y=tan(x)')

y4 = sin(2*x);
subplot(2,5,[6:7])
plot(x,y1)
title('y=sin(2x)')

y5 = cos(2*x);
subplot(2,5,[8:9])
plot(x,y2)
title('y=acos(2x)')

suptitle('my title');