จะเป็นประโยชน์มากขึ้นหากคุณวางตัวอย่างการทำงานที่สมบูรณ์มากขึ้น
ฉันลองทำสิ่งต่อไปนี้:
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()
นี้แน่นอนจะผลิต histogram บาร์กราฟกับแกน 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.