scipy.stats.cumfreq

scipy.stats.cumfreq(a, numbins=10, defaultreallimits=None, weights=None)[源代码]

使用直方图函数返回累积频率直方图。

累积直方图是一种映射,它计算所有面元中直到指定面元的观测值的累积数量。

参数
aarray_like

输入数组。

numbins整型,可选

用于直方图的仓位数。默认值为10。

defaultreallimits元组(下、上),可选

直方图范围的下限和上限。如果未给定值,则为略大于 a 是使用的。具体地说, (a.min() - s, a.max() + s) ,在哪里 s = (1/2)(a.max() - a.min()) / (numbins - 1)

weightsARRAY_LIKE,可选

中每个值的权重 a 。默认值为None,即为每个值赋予1.0的权重

退货
cumcountndarray

累计频率的入库值。

lowerlimit浮动

实际下限

binsize浮动

每个存储箱的宽度。

extrapoints集成

加分。

示例

>>> import matplotlib.pyplot as plt
>>> from numpy.random import default_rng
>>> from scipy import stats
>>> rng = default_rng()
>>> x = [1, 4, 2, 1, 3, 1]
>>> res = stats.cumfreq(x, numbins=4, defaultreallimits=(1.5, 5))
>>> res.cumcount
array([ 1.,  2.,  3.,  3.])
>>> res.extrapoints
3

创建具有1000个随机值的正态分布

>>> samples = stats.norm.rvs(size=1000, random_state=rng)

计算累计频率

>>> res = stats.cumfreq(samples, numbins=25)

计算x的值空间

>>> x = res.lowerlimit + np.linspace(0, res.binsize*res.cumcount.size,
...                                  res.cumcount.size)

绘制直方图和累计直方图

>>> fig = plt.figure(figsize=(10, 4))
>>> ax1 = fig.add_subplot(1, 2, 1)
>>> ax2 = fig.add_subplot(1, 2, 2)
>>> ax1.hist(samples, bins=25)
>>> ax1.set_title('Histogram')
>>> ax2.bar(x, res.cumcount, width=res.binsize)
>>> ax2.set_title('Cumulative histogram')
>>> ax2.set_xlim([x.min(), x.max()])
>>> plt.show()
../../_images/scipy-stats-cumfreq-1.png