Robin
Robin

Reputation: 83

Historgram function for matplotlib returning weird y-axis values

I am trying to understand the matplotlib.hist function. I have the following data:

cs137_count = np.array([this has a size of 750 and integers in the range from 1820 to 1980])
plt.figure()
plt.hist(cs137_count, density=True, bin = 50)  
plt.ylabel('Distribution')
plt.xlabel('Counts');

but the plot it provides has weird values for the y-axis in the range from 0 - 0.016 which makes no sense and I am not sure why it returns those values? I have attached an image of the plot below.

Image of plot

Upvotes: 0

Views: 181

Answers (1)

Reti43
Reti43

Reputation: 9796

That's because you're using density=True. From the docs

density: bool, optional

If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e., the area (or integral) under the histogram will sum to 1. This is achieved by dividing the count by the number of observations times the bin width and not dividing by the total number of observations. If stacked is also True, the sum of the histograms is normalized to 1.

Default is False.

Upvotes: 1

Related Questions