1
Python 3.6.1 :: Anaconda custom (64-bit)

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mtptlb

print (np.__version__)
1.12.1
print (mtptlb.__version__)
2.0.2

%matplotlib inline
a=np.random.uniform(1,100,1000000)
b=range(1,101)
plt.hist(a)

enter image description here

Why does the Y axis show 100000? np.random.uniform(1,100,1000000) has the value 1000000, so shouldn't it show 1000000 on y axis?

1 Answer 1

7

By default matplotlib.pyplot.hist uses 10 bins. So all your 1 million values are distributed into 10 bins. For a perfect uniform distribution you would expect that you have 100k occurrences (1 million divided by 10) in each bin.

You can change the number of bins, i.e.

a=np.random.uniform(1, 100, 1000000)
plt.hist(a, bins=100)

enter image description here

Here it's divided into 100 bins and because it's a uniform distribution all bins are roughly at 10000.

Or just one bin if you want a count of 1 000 000:

a=np.random.uniform(1, 100, 1000000)
plt.hist(a, bins=1)

enter image description here

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.