代码之家  ›  专栏  ›  技术社区  ›  Katharina Fürsatz

粗线宽无法区分的虚线

  •  1
  • Katharina Fürsatz  · 技术社区  · 6 年前

    我想增加图例中的线宽,同时还能看到这条线是虚线。我有一个简短的例子来说明我的意思

    for i=1:10
     x(i)=i;
     line1(i)=i;
     line2(i)=2*i;
    endfor
    
    subplot(2,1,1)
    plot(x,line1,"-","LineWidth",1,x,line2,"--","LineWidth",1)
    legend("solid","dashed")
    
    subplot(2,1,2)
    plot(x,line1,"-","LineWidth",10,x,line2,"--","LineWidth",10)
    legend("solid","dashed")
    

    这将显示以下图像 enter image description here

    正如您在第二张图片中看到的,只有一条线而不是虚线。

    2 回复  |  直到 6 年前
        1
  •  4
  •   Tasos Papastylianou    6 年前

    正如上面的评论所暗示的,破折号是在模仿图形本身中线条的属性,而且它太长,无法以有用的方式呈现(至少在您的特定示例的上下文中)。

    a = get(gcf, 'children');
    b = get(a(1), 'children');
    set(b(1), 'linestyle', ':');
    

    结果:

        2
  •  1
  •   Katharina Fürsatz    6 年前

    安迪的评论帮助我想出了另一种比塔索斯的方法。我增加了图例框的大小。仍然有一些需要发挥周围的确切位置和大小,但它的工作预期。

    for i=1:10
      x(i)=i;
      line1(i)=i;
      line2(i)=2*i;
    endfor
    
    subplot(2,1,1)
    plot(x,line1,"-","LineWidth",1,x,line2,"--","LineWidth",1)
    legend("solid","dashed")
    
    subplot(2,1,2)
    plot(x,line1,"-","LineWidth",10,x,line2,"--","LineWidth",10)
    hleg1=legend("solid","dashed")
    
    %added line
    set(hleg1,'position',[0.6 0.3 0.3 0.2])
    

    enter image description here