Chance Gordon
Chance Gordon

Reputation: 143

How to plot histogram of simulated geometric random variables using Python?

I must simulate 100,000 geometric random variables with parameter p = 0.01 and plot the results on a histogram, with buckets for each of the values 1 to 1000. What are buckets and how to I create the histogram? This is what I have so far.

p = 0.01
n = 100000
import numpy as np
import matplotlib.pyplot as plt 
y = np.random.geometric(p,n)

Upvotes: 1

Views: 711

Answers (1)

Jonski Goldstein
Jonski Goldstein

Reputation: 169

'Buckets' are the same as 'Bins', which are the range of values your data will fall into. So if your data ranges from 1-1000 and you want a bucket for each then you will need 1000 of them. If say you only had 100 bins it would group you data into 10's (1-10,11-20,21-30...)

Using matplotlib.pyplot which you already have imported you can use:

plt.figure()
plt.hist(y,bins=1000)
plt.show()

Upvotes: 1

Related Questions