I have a range of positive integers ranging from 250-1200, with a normal distribution. I have found the answer to creating bins of equal density (Matplotlib: How to make a histogram with bins of equal area?). What I am actually looking for is to be able to retrieve the upper and lower boundaries of each bin. Is there a library/function that exists for this? or can this information be pulled out from matplotlib?
Asked
Active
Viewed 373 times
1 Answers
2
Let's take a look at the code provided in the question you linked:
def histedges_equalN(x, nbin):
npt = len(x)
return np.interp(np.linspace(0, npt, nbin + 1),
np.arange(npt),
np.sort(x))
x = np.random.randn(1000)
n, bins, patches = plt.hist(x, histedges_equalN(x, 10))
bins
is actually giving you the edges of each bin as you can read in the docs of hist
function:

blunova
- 2,122
- 3
- 9
- 21
-
1that you for your rapid answer. – thejahcoop Jun 16 '22 at 14:45
-
1I have also added an example. – blunova Jun 16 '22 at 14:47
-
1not sure if this is giving me what I need. I am looking to generate bins that have an equal areas of density. I believe this still shows an equal-bin width histogram. I possibly need to play around with the statistic variable. – thejahcoop Jun 16 '22 at 16:04
-
1sorry! I have edited my answer! Hope it helps! – blunova Jun 16 '22 at 16:20
-
1fantastic. way simpler than I expected. I am truly grateful. – thejahcoop Jun 16 '22 at 16:22
-
1I have also added the link to the matplotlib `hist` function, look at `bins`. – blunova Jun 16 '22 at 16:24