用bin大小标准化直方图

时间:2017-09-18 13:30:38

标签: python matplotlib histogram

天文学直方图中的

通常用二进制大小进行归一化(这样直方图积分就是对象的总数)。

我想通过使用numpy以这种方式进行标准化的直方图,我想知道我是否可以直接使用matplotlib。

numpy版本的MWE:

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import powerlaw

NBINS = 50

RANGE = [0., 1.]
DELTA = (RANGE[1]-RANGE[0])/float(NBINS)

#--------
# fake data, pretty similar to the real ones
a=1.66
XX = powerlaw.rvs(a, size=1000)
#--------

n, bins = np.histogram(XX, NBINS, normed=False,
        range = RANGE)


ntot = np.sum(n)
n = np.asarray(n, dtype=float)
n/= DELTA

print 'Histogram integral = ', np.sum(n*DELTA), ' total objects = ', ntot
plt.bar(bins[:-1], n, DELTA, log=True)

plt.show()

0 个答案:

没有答案
相关问题