Bonjour,

Je suis en train de créer un graphe qui décrit la règle 68-95-99 pour une distribution normale, et il faut j'ajoute du texte pour décrire les segments, un peu comme ceci :



Voici mon code pour l'instant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def plot_line(ax, pt, mean, std):
    ax.plot([pt, pt], [0.0, scipy.stats.norm.pdf(pt, mean, std)], color='black', ls='--')
 
def plot_std(ax, pt1, pt2, c, mean, std):
    plot_line(ax, pt1, mean, std)
    plot_line(ax, pt2, mean, std)
    ptx = np.linspace(pt1, pt2, 10)
    pty = scipy.stats.norm.pdf(ptx,mean,std)
    ax.fill_between(ptx, pty, color=c, alpha='1.0')
 
x_min, x_max = -4., 4.
y_min, y_max = 0., .5
mean, std = 0., 1.
 
x = np.linspace(x_min, x_max, 100)
y = scipy.stats.norm.pdf(x, mean, std)
color = ['blue', 'red', 'green']
 
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x, y, color='black')
for k in range(3):
    plot_std(ax, mean + k * std, mean + (k + 1)*std, color[k], mean, std)
    plot_std(ax, mean - k * std, mean - (k + 1)*std, color[k], mean, std)
ax.grid(True)
ax.set_xlim(x_min, x_max)
ax.set_ylim(y_min, y_max)
ax.set_title('68-95-99.7 rule')
ax.set_xlabel('x')
ax.set_ylabel('Normal Distribution')