Removing a dot in a scatter plot with matplotlib

南笙酒味 提交于 2019-12-12 12:29:38

问题


The below code creates a scatter plot with a white dot. How can I remove this dot without redrawing the whole figure?

g = Figure(figsize=(5,4), dpi=60);
b = g.add_subplot(111)
b.plot(x,y,'bo') # creates a blue dot
b.plot(x,y,'wo') # ovverrides the blue dot with a white dot (but the black circle around it remains)

回答1:


Overplotting is not the same as removing. With your second plot call you draw a white marker, with a black border. You can set the edgecolor for a marker with plot(x,y,'wo', mec='w').

But if you really want to remove it, capture the returned line object, and call its remove method.

fig, ax = plt.subplots(subplot_kw={'xlim': [0,1],
                                   'ylim': [0,1]})


p1, = ax.plot(0.5, 0.5, 'bo') # creates a blue dot
p2, = ax.plot(0.5, 0.5, 'ro')

p2.remove()

The example above results in a figure with a blue marker. A red marker is added (in front) but also removed again.



来源:https://stackoverflow.com/questions/32965180/removing-a-dot-in-a-scatter-plot-with-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!