简体   繁体   English

如何删除命令“plt.plot(x,y)”绘制的点

[英]How to delete points drawn by command "plt.plot(x,y)"

I just want to delete points drawed by command "plt.plot(x,y)" in python package matplotlib.Would you give me some specific commands我只想删除由 python 包 matplotlib 中的命令“plt.plot(x,y)”绘制的点。你能给我一些具体的命令吗

            x,y=self.forward(x,y,v,target1)
            print a
            print x,y
            plt.plot(x, y, '*')

You cannot delete points from a line.您不能从一条线上删除点。 Three options you have:你有三个选择:

  • Remove the plot, create new plot删除情节,创建新情节

    import matplotlib.pyplot as plt import numpy as np x=np.array([1,3,4,6,7]) y=np.array([2,2,2,2,2]) line, = plt.plot(x, y, '*') #points to keep ind = [True,True,False,False,True] line.remove() newx = x[ind] newy = y[ind] line, = plt.plot(newx, newy, '*') plt.show()
  • Update data更新数据

    import matplotlib.pyplot as plt import numpy as np x=np.array([1,3,4,6,7]) y=np.array([2,2,2,2,2]) line, = plt.plot(x, y, '*') #points to keep ind = [True,True,False,False,True] newx = x[ind] newy = y[ind] line.set_data(newx, newy) plt.show()
  • Mark only subset of points仅标记点的子集

    import matplotlib.pyplot as plt import numpy as np x=np.array([1,3,4,6,7]) y=np.array([2,2,2,2,2]) line, = plt.plot(x, y, '*') #points to keep ind = [True,True,False,False,True] line.set_markevery(ind) plt.show()

Just like Ernest said: "You cannot delete points from a line".正如欧内斯特所说:“你不能从一条线上删除点”。

If you want to do this for some kind of animation, take a look at the animation module如果您想为某种动画执行此操作,请查看动画模块

Another highly not recommended hack would be 'paint over' the point with a color equal to the background.另一个极不推荐的 hack是用与背景相同的颜色“涂刷”点。

x_del = x[2]
y_del = y[2]
plt.plot(x_del, y_del, '*', color='white')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM