【问题标题】:Holding legend between a number of plots在多个地块之间保持图例
【发布时间】:2012-11-15 12:46:49
【问题描述】:

我使用不同的数据集进行绘图,并且所有绘图都在相同的轴上。我在这里面临的问题是添加图例,当我绘制下一个图时,第一个图例被覆盖我们的重叠。我怎样才能让连续情节的传说低于另一个而不是结束

谢谢

【问题讨论】:

    标签: matlab plot legend


    【解决方案1】:

    legends 的作用在于,每当您调用该命令时,它都会创建一个全新的图例。因此,您应该只绘制一次图例。

    这是一种不正确的方法:

    % THIS IS NOT CORRECT
    plot(x1, y1, 'r.');   legend('first plot')
    plot(x2, y2, 'g.');   legend('second plot')
    plot(x3, y3, 'b.');   legend('third plot')
    plot(x4, y4, 'k.');   legend('fourth plot')
    

    这将创建四个重叠的图例。 正确的方法是

    plot(x1, y1, 'r.');   
    plot(x2, y2, 'g.');   
    plot(x3, y3, 'b.');   
    plot(x4, y4, 'k.'); 
    
    % only 1 call to legend
    legend('first plot', 'second plot', 'third plot', 'fourth plot')  
    

    或者,或者,将情节和图例条目保持在一起,

    plot(x1, y1, 'r.');   L{1} = 'first plot';
    plot(x2, y2, 'g.');   L{2} = 'second plot';   
    plot(x3, y3, 'b.');   L{3} = 'third plot';   
    plot(x4, y4, 'k.');   L{4} = 'fourth plot'; 
    
    legend(L{:});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 2014-07-10
      • 2015-10-07
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      相关资源
      最近更新 更多