Explaination for bins parameter in axes.hist()

My Code:

fig = plt.figure(figsize=(5,20))
ax1 = fig.add_subplot(4,1,1)


I am confused with the use of “bins” parameter in the hist method of axes (confused even after reading from documentation and other sources). Is it for number of bars that should be present in the Histogram? Kindly help me out with this confusion.

Hello @joshi.ananya.joshi1 bins are the number of intervals you want to divide your data into

Have you thoroughly gone through the 3rd Step of the Histogram and Box Plots Mission?

The image they use there isn’t the best, but it should explain bins reasonably well.

1 Like


  1. okay, I got that bins are the divided data (in intervals) itself. Now about the range parameter, is this deciding that- if I choose range(0,5) i.e. [0,1,2,3,4], then data will be divided in specified number of bins but within the specified range only. Is it so?

  2. If we are using bins then it’s lower-class & upper-class values will be decided automatically or we can give manually too?

Yes, that’s correct. The image I shared from the Classroom above, the range is 0 to 5, and with the number of bins equal to 10. So, you can see each bin being of size 0.5.

The first bin would be from 0.0 to 0.5, and any values in your frequency distribution/data that is between 0.0 and 0.5 will be added to that first bin.

That’s what range is for. As per the Documentation -

range tuple or None, optional

The lower and upper range of the bins. Lower and upper outliers are ignored. If not provided, range is (x.min(), x.max()) . Range has no effect if bins is a sequence.

Now this is a little new, can you shed some light on this? @the_doctor

1 Like