我尝试为我的随机游走代码设置动画。我有两个要制作动画的列表,peopleX 和 peopleY。peopleX = [[-9, 9, -18], [-10, 9, -18], [-10, 9, -18], [-10, 10, -18], [-9, 10, - 17], [-10, 10, -18]] peopleY = [[-14, 16, 3], [-15, 15, 3], [-16, 15, 2], [-17, 15, 1 ], [-16, 16, 2], [-15, 16, 3]]
plt.style.use('seaborn')
fig = plt.figure()
ax = plt.axes(xlim=(xMin, xMax), ylim=(yMin, yMax))
line, = ax.plot([], [], lw=2)
ax.set_title('2D Random Walk', fontsize=18)
ax.set_xlabel('X', fontsize=16)
ax.set_ylabel('Y', fontsize=16)
ax.tick_params(labelsize=12)
def init():
# creating an empty plot/frame
line.set_data([], [])
return line,
xdata, ydata = peopleX, peopleY
def animate():
line.set_data(xdata, ydata)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,frames=n, interval=20, blit=True)
plt.show()
anim.save('output.gif', writer='ffmpeg')
但它没有显示任何东西。如果我尝试保存它总是显示的动画。
请帮我解决这个问题,非常感谢:)