import numpy as np
from scipy.stats import poisson
import matplotlib.pyplot as plt
#generate Poisson distribution with sample size 30000
x = poisson.rvs(mu=0.9, size=30000)
#create plot of Poisson distribution
plt.hist(x, density=True, edgecolor='black',bins=7,align='left')
fig, ax = plt.subplots(1, 1)
mu = 0.9
mean, var, skew, kurt = poisson.stats(mu, moments='mvsk')
x = np.arange(poisson.ppf(0.01, mu),
poisson.ppf(0.99, mu))
ax.plot(x, poisson.pmf(x, mu), 'red', ms=8, label='poisson pmf')
I use this code to draw two different graphs but it is not the outcome I expected.How can I modify my code to make the graph like the scatter point with the histogram.Thx!
The question is - plot the histogram using sample points generated above (set density = True, also adjust the number of bins to make the graph look nicer). Compare the results with the scatter plot using the Poison distribution formula directly.
