我尝试了多个动画示例代码,但无法使它们正常工作。这是我从Matplotlib文档中尝试的一个基本示例:
"""
A simple example of an animated plot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01) # x-array
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x+i/10.0)) # update the data
return line,
#Init only required for blitting to give a clean slate.
def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
interval=25, blit=True)
plt.show()
当我在IPython笔记本上执行上述代码时,只会看到生成的一个空白图。我已经尝试从多个服务器(包括Wakari)上运行此代码,在多台机器上使用多个浏览器(Chrome、Firefox、IE)都是如此。我可以很好地将动画保存为mp4文件,并在播放时看起来很棒。任何帮助都将不胜感激!