【问题标题】:How to get the data points of a particular bin in a weighted histogram?如何在加权直方图中获取特定 bin 的数据点?
【发布时间】:2020-09-01 15:01:33
【问题描述】:

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

我用它来绘制直方图:

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

ep 都有 130k 个数据点。 我喜欢获取特定 bin 的所有数据点(假设位在 -450)。

【问题讨论】:

  • 什么是 c、n 和 x?

标签: python histogram binning weighted-graph


【解决方案1】:

你可以试试这样的:

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

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

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多