已经提到的
FuncAnimation
有一个参数
frame
动画功能可以使用索引:
import matplotlib.pyplot as plt
import matplotlib.animation as anim
fig = plt.figure()
x=[20,23,25,27,29,31]
y=[10,12,14,16,17,19]
t=[2,9,1,4,3,9]
#create index list for frames, i.e. how many cycles each frame will be displayed
frame_t = []
for i, item in enumerate(t):
frame_t.extend([i] * item)
def init():
fig.clear()
#animation function
def animate(i):
#prevent autoscaling of figure
plt.xlim(15, 35)
plt.ylim( 5, 25)
#set new point
plt.scatter(x[i], y[i], c = "b")
#animate scatter plot
ani = anim.FuncAnimation(fig, animate, init_func = init,
frames = frame_t, interval = 100, repeat = True)
plt.show()
等效地,您可以在
ArtistAnimation
列表基本上
flipbook
方法
示例输出: