有没有办法在python中使用bin宽度= 0.1的bincount?

时间:2014-07-08 06:15:27

标签: python numpy plot width bin

我有类似的东西 [12.414261306701654, 10.52589457006108, 12.398125569114093, 11.900971715356471, 11.566273761189997, 10.31504117886884, 10.235859974871904, 10.25704925592012, 10.296557787801154, 10.19010244226054]

说我想要(10,10.1)(10.1,10.2),...

中的出现次数

我认为numpy.bincount只取整数bin宽度,但是如果我将我的数组乘以10并使用bincount,那么当我稍后绘制结果时xscale也会关闭10 ,我不知道如何才能得到准确的情节。

感谢

1 个答案:

答案 0 :(得分:1)

查看np.histogram

>>> import numpy as np
>>> data = [12.414261306701654, 10.52589457006108, 12.398125569114093, 11.900971715356471, 11.566273761189997, 10.31504117886884, 10.235859974871904, 10.25704925592012, 10.296557787801154, 10.19010244226054]
>>> counts, bin_edges = np.histogram(data, bins=np.arange(10, 12.6, 0.1))
>>> counts
array([0, 1, 3, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
       1, 1])