一组子图的标题

Title over a group of subplots

我想要一个图,里面有六个图;我把它和子图分开了。例如

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

我想添加两个全局标题,假设一个全局标题用于左侧的六个地块,另一个标题用于右侧的其他六个地块。

我没有2018b版本,所以无法使用sgtitle('Subplot Title');。有可能以某种方式使用 suptitle('my title'); 吗? 我可以使用 text() 但调整 window 的大小后,两个标签会移动。

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

代码

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

备注:

不要使用ij作为迭代变量,因为它们已经在MATLAB的命名空间中定义为虚数单位。

你可以使用 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{:})