Hello, I need to plot graphs of some statistical distributions using python3, so I checked the scipy documentation from there, after making some changes to my needs, I got the following code to perform a normal distribution:
valor = [1,2,3,4,5,6,3]
from scipy.stats import norm
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
# Calculate a few first moments:
mean, var, skew, kurt = norm.stats(moments='mvsk')
print(norm.stats(moments='mvsk'))
# Display the probability density function (''pdf''):
x = np.linspace(norm.ppf(0.01), norm.ppf(0.99), 100)
print(norm.ppf(0.01))
ax.plot(x, norm.pdf(x),'r--', lw=5, alpha=0.6, label='norm pdf')
rv = norm()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
vals = norm.ppf([0.001, 0.5, 0.999])
np.allclose([0.001, 0.5, 0.999], norm.cdf(vals))
r = valor
# And compare the histogram:
ax.hist(r, bins=len(valor), normed=True ,alpha=0.6, color='g', edgecolor='black', linewidth=1.2)
ax.legend(loc='best', frameon=False)
plt.savefig("templates/docNORMAL.png")
#plt.show()
plt.gcf().clear()
But I was only able to use the example with the numbers, when using a list with 100 random values it has errors:
Whenitshouldlooklikethis:
I need to know how to make a list work with the documentation examples so that I can implement the others.