0
我写了一个简单的动画代码。该代码创建随机点,然后在动画过程中绘制它们。Python动画更新
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
x = 10*np.random.rand(10,1)
y = 10*np.random.rand(10,1)
fig = plt.figure()
ax = plt.axes(aspect='equal',xlim =(-10,10), ylim = (-10,10))
plts = ax.plot([], [], 'o-')
def init():
plts.set_data([],[])
return plts
def animate(num,x,y,plots,skip):
plts[0].set_data(x[:num*skip],y[:num*skip])
return plts
skip = 1
ani = animation.FuncAnimation(fig,
animate,
frames=10,
fargs =(x,y,plts,skip),
interval=1000)
plt.show()
在动画过程中,代码会绘制所有点。 有人可以告诉我如何绘制一个框架中的一个点,并清除前一点?