【发布时间】:2020-04-10 19:54:20
【问题描述】:
我正在尝试使用 matplotlib.animation 创建一个动画直方图,但 animation.FuncAnimation 无法正常运行:使用此代码时,我在官方文档中找到,
"""
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)
line, = ax.plot(x, np.sin(x))
def animate(i):
print(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()
我得到的最终结果是由 init() 函数创建的图(也是一个空图),但没有动画迭代。此外,我测试了其他代码,实际上给了我相同的结果:我得到了初始化,或第一帧,但没有更多。 matplotlib 和 matplotlib.animation 已安装,一切似乎都很好,除了它不起作用。有人知道如何解决它吗? (提前谢谢你:)!)
【问题讨论】:
-
您在哪里以及如何运行它?你有哪些版本的python、matplotlib?
-
对不起,我刚刚看到你的评论 x) !我在我的 IPython 控制台中使用 Spyder 在 Python 3.6 下运行我的程序,我的 matplotlib 版本是 2.0.2!
标签: python matplotlib