python matplotlib dash-dot-dot - how to?

后端 未结 1 1397
庸人自扰
庸人自扰 2020-12-13 09:20

I am using python and matplotlib to generate graphical output.
Is there a simple way to generate a dash-dot-dot line-style?
I am aware of the \'--\',

1条回答
  •  囚心锁ツ
    2020-12-13 09:54

    You can define custom dashes:

    import matplotlib.pyplot as plt
    
    line, = plt.plot([1,5,2,4], '-')
    line.set_dashes([8, 4, 2, 4, 2, 4]) 
    plt.show()
    

    enter image description here

    [8, 4, 2, 4, 2, 4] means

    • 8 points on, (dash)
    • 4 points off,
    • 2 points on, (dot)
    • 4 points off,
    • 2 points on, (dot)
    • 4 points off.

    @Achim noted you can also specify the dashes parameter:

    plt.plot([1,5,2,4], '-', dashes=[8, 4, 2, 4, 2, 4])
    plt.show()
    

    produces the same result shown above.

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