How To Get The Data Points Of A Particular Bin In A Weighted Histogram?
I have a weighted histogram in python and I like to have all the data point of a particular bin. I use this to plot the histogram: c,n,x=plt.hist(e, bins=50, range=(-500, -400), w
Solution 1:
You may try something like this:
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])
Example:
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])
Output->
0.011885780547905494
Hope, this may help!
Post a Comment for "How To Get The Data Points Of A Particular Bin In A Weighted Histogram?"