动画在python中没有发生

时间:2017-12-29 09:36:36

标签: python

我正在尝试使用matplotlib.animation在python中制作动画图,并且包存在。但是当我执行程序时,它没有显示任何错误,但也没有动画。

%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation as animation
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.arrange(-4,4,0.5)
    plt.hist(x[:curr],bins=bins)
    plt.axis([-4,4,0,30])
    plt.gca().set_title('Sampling the normal distribution')
    plt.gca().set_xlabel('Value')
    plt.gca().set_ylabel('Frequency')
    plt.annotate('n={}'.format(curr),[3,27])


    fig = plt.figure() 
    a = animation.FuncAnimation(fig,update,interval =100)

期待解决方案。

谢谢。

0 个答案:

没有答案