一组子图的标题

时间:2019-01-23 14:18:42

标签: matlab matlab-figure

我想要一个有六个地块的图;我用子图分割它。例如

for i = 1:12
    subplot(3,4,i)
    plot(peaks)
    title(['Title plot ',num2str(i)])
end

我想添加两个全局标题,比方说左侧六个图的全局标题,以及右侧六个其他图的另一个标题。

enter image description here

我没有2018b版本,所以我不能使用sgtitle('Subplot Title');。是否可以以某种方式使用suptitle('my title');? 我可以使用text(),但要调整窗口大小,两个标签会移动。

2 个答案:

答案 0 :(得分:1)

为此,您可以使用annotation以及子图1和3的位置。

for k = 1:12
    sp(k) = subplot(3,4,k);
    plot(peaks)
    title(['Title plot ',num2str(k)])
end
spPos = cat(1,sp([1 3]).Position);
titleSettings = {'HorizontalAlignment','center','EdgeColor','none','FontSize',18};
annotation('textbox','Position',[spPos(1,1:2) 0.3 0.3],'String','Left title',titleSettings{:})
annotation('textbox','Position',[spPos(2,1:2) 0.3 0.3],'String','Right title',titleSettings{:})

enter image description here

答案 1 :(得分:0)

我没有对此进行测试,但是您可以获取子图对象的句柄,然后对该句柄执行title方法。我还建议在循环后再应用标题。

代码

style={[styles.default, {height: Math.min(Math.max(35, this.state.height),120)}]}

备注:

请勿使用for k = 1:12 h(k) = subplot(3, 4, i) plot(peak) end title(h(1), 'Left side') title(h(8), 'Right side') % find out the right index yourself i作为迭代变量,因为它们已在MATLAB的命名空间中定义为虚数单元。