使用matplotlib删除散点图中的点(Removing a dot in a scatter plot with matplotlib)

编程入门 行业动态 更新时间:2024-10-25 09:40:49
使用matplotlib删除散点图中的点(Removing a dot in a scatter plot with matplotlib)

下面的代码创建一个带有白点的散点图。 如何在不重新绘制整个图形的情况下删除此点?

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)

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)

最满意答案

重叠绘图与移除不同。 随着你的第二个阴谋称你画一个白色的标记,黑色的边框。 你可以用plot(x,y,'wo', mec='w')设置一个标记的边缘颜色。

但是如果你真的想删除它,捕获返回的行对象,并调用它的remove方法。

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()

上面的例子产生一个带有蓝色标记的图。 红色标记被添加(在前面),但也被删除。

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.

更多推荐

本文发布于:2023-07-26 03:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   Removing   matplotlib   plot   scatter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!