# Integer equal-width bins for histograms

Hi,
When histogramming integer data, is there an easy way to tell matplotlib that I want a certain number of bins, and each bin to cover an equal number of integers (except possibly the last one)? (in order to avoid having some bins higher than others merely because they cover more integers)

I know I can pass in an explicit bins array (something like list(range(min, max, (max-min)//n)) + max) but I was hoping for something simpler, like hist(data, nbins=42, equal_integer_coverage=True).
Best,
Antony

Hi,
When histogramming integer data, is there an easy way to tell
matplotlib that I want a certain number of bins, and each bin to
cover an equal number of integers (except possibly the last one)?
(in order to avoid having some bins higher than others merely because
they cover more integers) I know I can pass in an explicit bins array
(something like list(range(min, max, (max-min)//n)) + max) but I was
hoping for something simpler, like hist(data, nbins=42,
equal_integer_coverage=True). Best,
Antony

Int data is discrete. For discrete variables you don't need bins, you
don't estimate the frequency distribution you know it exactly by
counting.

Of course you could do that with the hist function:

···

Am Thu, 29 May 2014 14:14:52 -0700 schrieb Antony Lee <antony.lee@...1016...>:

pl.hist(r, np.arange(min(r)-0.5, max(r)+1.5), histtype='step')

I can still need to bin data, e.g. when the data range is “large”, or at least not small compared to the number of data points.
Antony

···

2014-05-30 5:03 GMT-07:00 Yoshi Rokuko <yoshi@…3676…>:

Am Thu, 29 May 2014 14:14:52 -0700

schrieb Antony Lee <antony.lee@…1016…>:

Hi,

When histogramming integer data, is there an easy way to tell

matplotlib that I want a certain number of bins, and each bin to

cover an equal number of integers (except possibly the last one)?

(in order to avoid having some bins higher than others merely because

they cover more integers) I know I can pass in an explicit bins array

(something like list(range(min, max, (max-min)//n)) + max) but I was

hoping for something simpler, like hist(data, nbins=42,

equal_integer_coverage=True). Best,

Antony

Int data is discrete. For discrete variables you don’t need bins, you

don’t estimate the frequency distribution you know it exactly by

counting.

Of course you could do that with the hist function:

pl.hist(r, np.arange(min®-0.5, max®+1.5), histtype=‘step’)

Time is money. Stop wasting it! Get your web API in 5 minutes.