Simple exemple sur comment tracer une loi normale asymétrique avec python et matplotlib (source)
[image:normal-skewed-distribution]
from scipy import linspace
from scipy import pi,sqrt,exp
from scipy.special import erf
import matplotlib.pyplot as plt
def pdf(x):
return 1/sqrt(2*pi) * exp(-x**2/2)
def cdf(x):
return (1 + erf(x/sqrt(2))) / 2
def skew(x,e=0,w=1,a=0):
t = (x-e) / w
return 2 / w * pdf(t) * cdf(a*t)
# You can of course use the scipy.stats.norm versions
# return 2 * norm.pdf(t) * norm.cdf(a*t)
x = linspace(0,30,100)
e = 5.0 # location
w = 6.0 # scale
a = 10
p = skew(x,e,w,a)
plt.plot(x,p)
plt.scatter(x,p)
plt.title('Loi normale asymetrique')
plt.grid()
plt.xlim(0,30)
plt.savefig('normal_skewed_distribution.png',bbox_inches='tight')
plt.show()
Recherches associées
Liens | Site |
---|---|
skew normal distribution in scipy | stackoverflow |
Skew normal distribution | wikipedia |
Loi normale asymétrique | wikipedia |