1

我正在做我的第一个 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)

PS我在jupyter笔记本上编码

4

1 回答 1

1

我得到了我的答案。这是 plt.hist 调用中的错字。参数bins不是bin
plt.hist(X[:curr], bins=bins)

于 2020-07-26T02:22:31.603 回答