直方图python高度_python – 子图中直方图的动画

normed =直方图的True参数使直方图绘制分布的密度.从the documentation开始:

normed : boolean, optional

If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e., n/(len(x)`dbin), i.e., the integral of the histogram will sum to 1. If stacked is also True, the sum of the histograms is normalized to 1.

Default is False

这意味着直方图条的高度取决于箱宽度.如果仅绘制一个数据点,则动画开始时的情况下,条形高度将为1./binwidth.如果箱宽度小于零,则杆高度可能变得非常大.

因此,在整个动画过程中修复分档并使用它们是个好主意.

清除轴也是合理的,这样就不会绘制100个不同的直方图.

import numpy as np

from matplotlib.pylab import *

import matplotlib.animation as animation

# generate 4 random variables from the random, gamma, exponential, and uniform distribution

x1 = np.random.normal(-2.5, 1, 10000)

x2 = np.random.gamma(2, 1.5, 10000)

x3 = np.random.exponential(2, 10000)+7

x4 = np.random.uniform(14,20, 10000)

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

def updateData(curr):

if curr <=2: return

for ax in (ax1, ax2, ax3, ax4):

ax.clear()

ax1.hist(x1[:curr], normed=True, bins=np.linspace(-6,1, num=21), alpha=0.5)

ax2.hist(x2[:curr], normed=True, bins=np.linspace(0,15,num=21), alpha=0.5)

ax3.hist(x3[:curr], normed=True, bins=np.linspace(7,20,num=21), alpha=0.5)

ax4.hist(x4[:curr], normed=True, bins=np.linspace(14,20,num=21), alpha=0.5)

simulation = animation.FuncAnimation(fig, updateData, interval=50, repeat=False)

plt.show()

SQ9kc.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值