【发布时间】:2020-07-25 15:44:02
【问题描述】:
我正在做我的第一个 matplotlib 动画图。而且它不起作用。请有人解释一下,为什么??
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
n = 100
X = np.random.randn(n)
def update(curr):
if curr == n:
a.event_source.stop()
plt.cla()
bins = np.arange(-4,4, 0.5)
plt.hist(X[:curr], bin=bins)
plt.axis([-4,4,0,30])
plt.annotate("n={}".format(curr),(3,27))
fig = plt.figure()
a = animation.FuncAnimation(fig, update, interval=100)
附:我在 jupyter notebook 上编码
【问题讨论】:
-
你试过
plt.show()吗? -
是的。试过了,没用。
-
能否请您提供完整的可重现代码?
curr变量无法识别。 -
其实我正在做一个数据可视化的 coursera 课程,教授告诉我,corr 是一个递归变量,每次函数运行后都会自动更新。
-
哦,我明白了。我建议你在 coursera 论坛上问这个。
标签: python-3.x matplotlib-animation