直方图python高度_python – 绘制直方图,其高度和在matplotlib中为1

如果你提出了一个更完整的工作(或在这种情况下非工作)的例子将更有帮助。

我试过以下:

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, normed=True)

fig.canvas.draw()

plt.show()

这将确实产生具有从[0,1]开始的y轴的条形图直方图。

此外,根据hist文档(即axython从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。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值