Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Matplotlib histogram missing bars

I am trying to plot a histogram using the code below:

plt.subplots(figsize = (10,6))

lbins=[0,85,170,255,340,425]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

plt.hist(flt_data[‘tree_dbh’], bins=lbins)

plt.gca().set(title=’Tree diameter histogram’, ylabel=’Frequency’)

The output is as follows:
Histogram

The output is not including all data in the histogram.

The following are the descriptive statistics of the column:

Descriptive statistics

>Solution :

It looks like all your data is in the the first bar. It’s not that the bars or missing it’s just that their values are very small compared to the first one.

You have 652173 point values and with a mean value of 11.7 and a std of 8.6. This means that the maximum value which is 425 is most likely an outlier.

Try doing it with:

lbins = np.arange(0,100, 10)

also you can take a look at len(flt_data['tree_dbh'][flt_data['tree_dbh'] > 85]) it will inform you how many points are counted in the other bars that you don’t see

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading