Why do histogram bars vanish when we keep the bins value high in matplotlib?

Also, the histogram bar widths are different on certain values of bin. How to keep the bar widths uniform? I have tried using the rwidth but that dos not solve my problem.

Data:

test    age
17 - Alpha OH PROGESTERONE - HORMONE ASSAYS 23
17 - Alpha OH PROGESTERONE - HORMONE ASSAYS 26
17 ALPHA HYDROXY PROGESTERONE   18
17 ALPHA HYDROXY PROGESTERONE   21
17 ALPHA HYDROXY PROGESTERONE   25
17 ALPHA HYDROXY PROGESTERONE   27

Code

axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(0, 100)
plt.hist(df.loc[0:1,'age':'age'].to_numpy(),100, rwidth=0.9)

axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(0, 100)
plt.hist(df.loc[2:5,'age':'age'].to_numpy(),10, rwidth=0.9)

axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(0, 100)
plt.hist(df.loc[6:14,'age':'age'].to_numpy(),100, rwidth=0.9)

Topic matplotlib historgram

Category Data Science


The height of a bar shows the number of measurements within that range.

The bars get shorter when you increase the bin count, because the more bins you have in total, the less measurements fall into an individual bin.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.