代码之家  ›  专栏  ›  技术社区  ›  Shika93

一组子批次的标题

  •  1
  • Shika93  · 技术社区  · 6 年前

    我想要一个里面有六个图的数字,我用子图把它分开。例如

    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 回复  |  直到 6 年前
        1
  •  1
  •   EBH    6 年前

    你可以使用 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

        2
  •  0
  •   Sven Krüger    6 年前

    我没有测试这个,但是您可以获取子块对象的句柄,然后在这个句柄上执行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
    

    备注:

    不要使用 i j 作为迭代变量,它们已经在matlab的名称空间中定义为虚单位。