小编Lok*_*yal的帖子

Python 中的直方图动画

我正在尝试使用动画制作直方图,但它没有显示。

#using animation library

%matplotlib notebook
import pandas as pd
import numpy as np
import matplotlib.animation as animation
import matplotlib.pyplot as plt

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],bins=bins)
    plt.axis([-4,4,0,30])
    plt.gca().set_title('sampling the normal distribution')
    plt.gca.set_ylabel('frequency')
    plt.gca().set_xlabel('value')
    plt.annoate('n={}'.format(curr),[3,27])
    
    
    
fig=plt.figure()
a=animation.FuncAnimation(fig,update,interval=100)    
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib histogram python-3.x

6
推荐指数
1
解决办法
6585
查看次数

标签 统计

animation ×1

histogram ×1

matplotlib ×1

python ×1

python-3.x ×1