0

我在 python 中有一个加权直方图,我喜欢拥有特定 bin 的所有数据点。

我用它来绘制直方图:

c,n,x=plt.hist(e, bins=50,  range=(-500, -400), weights=p, color='blue')

e两者p都有 130k 数据点。我喜欢获取特定 bin 的所有数据点(让我们说位在 -450)。

4

1 回答 1

0

你可以尝试这样的事情:

c,n,x=plt.hist(e, bins=50,  range=(-500, -400), weights=p, color='blue')
ind = np.where(n == -450)[0][0]
print(c[ind])

例子:

np.random.seed(0)

#data
mu = -450  # mean of distribution
sigma = 50  # standard deviation of distribution
x = mu + sigma * np.random.randn(10000)

num_bins = 50

# the histogram of the data
n, bins, patches = plt.hist(x, num_bins, density=True,  range=(-500, -400))

ind = np.where(bins == -450)[0][0]
print(n[ind])

输出->

0.011885780547905494

希望,这可能会有所帮助!

于 2020-09-01T15:55:09.113 回答