# Approaches to choosing number of bins in histogram

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)

• This might help: stats.stackexchange.com/questions/798/… Also there's this Sturges rule whose formula is similar to your code. Jan 24 '20 at 0:07