动画散点图(删除之前的点)

问题描述 投票:0回答:0

我想制作一个只显示当前点并删除最后一个点的散点图。我已经有一个运行良好的代码,但我不知道如何删除之前的点。

这是我的代码:

img = plt.imread("/Users/hadis/Desktop/project/5_Data/08_background.png") 
fig, ax = plt.subplots()
plt.imshow(img,extent=[0,1170,-780,0]) 

x2 = new_x[:,0]
y2 = new_x[:,1]

scat = ax.scatter(x2,y2,s=10)

def animate(i):
    scat.set_offsets(np.hstack((x2[:i], y2[:i])))
    return scat,

ani = animation.FuncAnimation(fig, animate, repeat=False,
                                frames=len(x2) , interval=20, blit= False)

plt.show()
python matplotlib animation scatter-plot point
© www.soinside.com 2019 - 2024. All rights reserved.