0

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

2
  • [this has a size of 750 and integers in the range from 1820 to 1980]--> np.random.random_integers(1820,1980,750) Commented Feb 12, 2021 at 3:21
  • Y of 0.016 for x=1900 means there is about 1.6% chance that x=1900 Commented Feb 12, 2021 at 12:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.