【问题标题】:title in subplot and xlabel子图和 xlabel 中的标题
【发布时间】:2014-03-14 17:49:33
【问题描述】:

我在下面编写了代码来使用 subplot 在窗口中绘制图形。 但是对于标记,只有第一个子图被标记 我该怎么办? 标题也存在这个问题。

stem(n, h1);
xlabel('n');
ylabel('h1');
subplot(212)
stem(n, h2);
xlabel('n');
ylabel('h2');

【问题讨论】:

  • 我想你忘了在stem(n,h1)之前添加subplot(211)
  • 在继续之前将子图更正为 subplot(2,1,2),已经看到 matlab 版本在这种语法上给出错误。虽然它应该工作。还要添加@Divakar 所指出的第一个子图

标签: matlab matlab-figure matlab-guide matlab-compiler


【解决方案1】:

一般来说,如果您在创建图形/轴时将句柄返回给它们,则可以通过将该句柄作为第一个参数传递给绘图修改函数来定制每个部分。

如果你这样做了

a1 = subplot(2,1,1);
a2 = subplot(2,1,2);

你可以这样做

xlabel(a1, 'title here', 'FontSize', 12)
xlabel(a2, 'other title', 'FontWeight', 'bold')

或您想要的任何其他特定于标签的自定义。

【讨论】:

    【解决方案2】:

    要创建带有单独标题的子图 - 循环它们:

    Titles= {'Title One' 'Title Two'} 
    
    figure;
    for i = 1:2;
        subplot(1,2,i);
        plot(x,y(:,i);
        title(Titles(i));
    end
    

    此外,如果您想要 main 标题和 X & Y 标签覆盖 all 子图,则此代码很方便:http://www.mathworks.com/matlabcentral/fileexchange/7772-suplabel ...但它需要您的代码额外运行约 13 秒。

    【讨论】:

      猜你喜欢
      • 2018-01-19
      • 2016-05-14
      • 2017-07-02
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 2018-05-22
      相关资源
      最近更新 更多