我有两个数组x和y,每个数组都有超过365000个元素。我想用这些数组元素画一条动画线。我在用matplotlib.animation为了它。问题是当我执行下面的代码时,我看不到平滑(动画)绘制的图形。相反,我看到的是最终的绘图版本。在
这是我的代码:#libs
# Movement instance creation-----------------------------
movement1=Movement(train1, track1)
# # Move the train on the track
movement1.move()
y = movement1.speed
x = movement1.pos
Writer = animation.writers['ffmpeg']
writer = Writer(fps=20, metadata=dict(artist='Me'), bitrate=1800)
fig = plt.figure()
ax = plt.axes(xlim=(0, 25), ylim=(0, 300))
line, = ax.plot([], [], lw=2)
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
# animation function. This is called sequentially
def animate(i):
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=200, blit=True)
anim.save('basic_animation.mp4', writer=writer)
以下是我预期的类似结果:
当然,我的图表是另一条曲线。在