Linewidth is added to the length of a line

前端 未结 1 1353
我在风中等你
我在风中等你 2020-12-24 12:46

When I draw a line segment in matplotlib the linewidth seems to be added to the length of the line. Below my code (not the most pythonic code, but it should do the trick). A

相关标签:
1条回答
  • 2020-12-24 12:59

    It looks like the default solid_capstyle is projecting, which isn't the one you want:

    plt.figure()
    plt.plot([0, 100], [5, 5], linewidth=50, linestyle="-", c="blue",
             solid_capstyle="butt")
    plt.plot([0, 100], [15, 15], linewidth=50, linestyle="-", c="red",
             solid_capstyle="round")
    plt.plot([0, 100], [25, 25], linewidth=50, linestyle="-", c="purple",
             solid_capstyle="projecting")
    plt.axvline(x=100, c="black")
    plt.xlim(0, 125)
    plt.ylim(0, 30)
    plt.savefig("cap.png")
    

    enter image description here

    0 讨论(0)
提交回复
热议问题