numpy - How do I show a plot of Random.gammavariate distribution? -


i little confused @ different distribution functions out there (i.e. numpy, scipy, matploglib.mlab, , random)

i trying sampling of gamma distribution numbers use program , plot out distribution being used well.

so far doing:

import random import matplotlib.pyplot plt import matplotlib.mlab mlab import scipy.special sps import numpy np  k = 2.0 theta = 2.0 random.gammavariate(k, theta) # gives me results of gamma distribution  # unfortunately, doesn't work # plt.plot(random.gammavariate(k, theta)) # plt.show()  # works somehow if don't specify  # bins , y - copied https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.gamma.html # , seems work s = np.random.gamma(k, theta, 1000) plt.plot(bins, y, linewidth=2, color='r') 

any explaining me appreciated.

you trying plot curve (or scatter) of 1 dimensional data. can show distribution plotting histogram:

plt.hist(np.random.gamma(k, theta,100 )) 

note 1000 give 1000 points. if want extract informations histogram bins:

 count, bins, ignored = plt.hist(np.random.gamma(k, theta, 100)) 

then can plot plt.plot takes 2d input:

plt.plot(bins, y) 

where y given by:

import scipy.special sps import numpy np y = bins**(k-1)*(np.exp(-bins/theta) /(sps.gamma(k)*theta**k)) 

which gamma function.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -