Custom plot linestyle in matplotlib

后端 未结 2 897
面向向阳花
面向向阳花 2020-12-18 06:13

I\'m trying to achieve graph using matplotlib with lines with whitespaces near points like in this one:


(source: simplystatistics.org)

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 06:51

    Is it an option to just make a thick white border around your markers? Its not a custom linestyle but a simple way to get a similar effect:

    y = np.random.randint(1,9,15)
    
    plt.plot(y,'o-', color='black', ms=10, mew=5, mec='white')
    plt.ylim(0,10)
    

    enter image description here

    Here the key are the arguments

    • mec='white', white marker edge color
    • ms=10, markersize 10 points (this is rather large),
    • mew=5, marker edge width 5 points, such that effectively the points are 10-5=5 points large.

提交回复
热议问题