Choosing the number of bins in a histogram has always been something that gets me thinking a lot. Based on the number of bins chosen, the graph at time looks a lot different and also could lead to different interpretations.

Below is the square-root rule, which I use as the thumb-rule for selecting the number of bins in most occasions.

Posting this question here to hear other opinions.

data_pts = len(np.array(data))
bin_cnt = int(np.sqrt(data_pts))

plt.hist(data, bins=bin_cnt)
  • 1
    $\begingroup$ This might help: stats.stackexchange.com/questions/798/… Also there's this Sturges rule whose formula is similar to your code. $\endgroup$ – Fatemeh Asgarinejad Jan 24 '20 at 0:07
  • 1
    $\begingroup$ Thanks @FatemehAsgarinejad, that answer does cover a number of methods. $\endgroup$ – loki Jan 24 '20 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.