【问题标题】:How to set position of subplot in matlab如何在matlab中设置子图的位置
【发布时间】:2018-06-19 12:46:13
【问题描述】:

我尝试一个接一个地设置这个子图,但不能改变它们的位置。我能做什么?

figure
subplot(10,1,1,'Position',[0.5,0.69,1,0.1]);plot(B{1, 1}(:,[1,3]),'Color', 
[0,0,0]);legend('Black');
subplot(10,1,2,'Position',[0.5,0.37,1,0.1]);plot(B{2, 1}(:,[1,3]),'Color', 
[1,0,0]);legend('Red');
subplot(10,1,3,'Position',[0,0,1,0.1]);plot(B{3, 1}(:,[1,3]),'Color', 
[0,1,0]);legend('Lime');
subplot(10,1,4,'Position',[0,0,1,0.1]);plot(B{4, 1}(:,[1,3]),'Color', 
[0,0,1]);legend('Blue');
subplot(10,1,5,'Position',[0,0,1,0.1]);plot(B{5, 1}(:,[1,3]),'Color', 
[0,1,1]);legend('Cyan');
subplot(10,1,6,'Position',[0,0,1,0.1]);plot(B{6, 1}(:,[1,3]),'Color', 
[1,0,1]);legend('Magenta');
subplot(10,1,7,'Position',[0,0,1,0.1]);plot(B{7, 1}(:,[1,3]),'Color', 
[0.5,0.5,0.5]);legend('Gray');
subplot(10,1,8,'Position',[0,0,1,0.1]);plot(B{8, 1}(:,[1,3]),'Color', 
[0.5,0,0]);legend('Maroon');
subplot(10,1,9,'Position',[0,0,1,0.1]);plot(B{9, 1}(:,[1,3]),'Color', 
[0.5,0,0.5]);legend('Purple');
subplot(10,1,10,'Position',[0,0,1,0.1]);plot(B{10, 1}(:,[1,3]),'Color', 
[0,0.5,0.5]);legend('Teal');

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    嗯,你可以改变位置,只要你做得好。

    manual of the subplot中所说,可以指定位置:

    • 自动

    通过使用

    subplot(m,n,p)
    

    p 位置使用m x n 网格绘图。这是你部分使用的。

    • 手动

    通过使用

    subplot('Position',[left bottom width height])      
    

    这就是你有问题的地方。正如手册中所述,如果重叠,它将擦除下面的图形。 在您的情况下,有几个位置是重叠的。
    另请注意,位置始终是标准化的,因此带有width=1left=0.5 意味着您在x 方向上裁剪了一半的图形。使用手动定位时要注意。
    正如Cris Luengo's answer 所指出的,您可以直接使用axis。这有一些优点和缺点。然而axis 中的单位也被标准化。所以,知道你在用什么。

    当您同时使用(手动和自动)设置时,我不清楚哪一个会有偏好,因为当我测试您的部分代码时得到不同的输出。

    【讨论】:

    • 关于 OP 使用的坐标的要点。 8 个轴的位置相同,这是不可能的。
    【解决方案2】:

    如果您要手动设置它们的位置,只需直接创建轴对象:

    figure
    axes('Position',[0.5,0.69,1,0.1]);plot(B{1, 1}(:,[1,3]),'Color', 
    [0,0,0]);legend('Black');
    axes('Position',[0.5,0.37,1,0.1]);plot(B{2, 1}(:,[1,3]),'Color', 
    [1,0,0]);legend('Red');
    

    Documentation to axes.

    subplot 的好处在于它可以为您放置坐标轴。它没有其他目的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      • 2015-11-20
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多