Было бы более полезно, если бы вы представили более полный рабочий (или в данном случае нерабочий) пример.
Я попробовал следующее:
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(1000)
fig = plt.figure()
ax = fig.add_subplot(111)
n, bins, rectangles = ax.hist(x, 50, density=True)
fig.canvas.draw()
plt.show()
Это действительно приведет кгистограмма гистограммы с осью Y, которая идет от [0,1]
.
Далее, согласно документации hist
(то есть ax.hist?
из ipython
), я думаю, что сумма тоже хорошая:
*normed*:
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)``. In a probability density, the integral of
the histogram should be 1; you can verify that with a
trapezoidal integration of the probability density function::
pdf, bins, patches = ax.hist(...)
print np.sum(pdf * np.diff(bins))
Попытка после команд выше:
np.sum(n * np.diff(bins))
Я получаю возвращаемое значение 1.0
, как и ожидалось.Помните, что normed=True
не означает, что сумма значений на каждом столбце будет равна единице, а интеграл по столбцам равен единице.В моем случае np.sum(n)
вернул примерно 7.2767
.