Personnaliser les préférences

Nous utilisons des cookies pour vous aider à naviguer efficacement et à exécuter certaines fonctions. Vous trouverez ci-dessous des informations détaillées sur tous les cookies sous chaque catégorie de consentement.

Les cookies classés comme « Nécessaires » sont stockés sur votre navigateur car ils sont essentiels pour activer les fonctionnalités de base du site.... 

Toujours actif

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Aucun cookie à afficher.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Aucun cookie à afficher.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Aucun cookie à afficher.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Aucun cookie à afficher.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

Aucun cookie à afficher.

Comment créer une courbe en cloche en Python



Une « courbe en cloche » est le surnom donné à la forme d’unedistribution normale , qui a une forme distincte en « cloche » :

Courbe en cloche en Python

Ce tutoriel explique comment créer une courbe en cloche en Python.

Comment créer une courbe en cloche en Python

Le code suivant montre comment créer une courbe en cloche à l’aide des bibliothèques numpy , scipy et matplotlib :

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

#create range of x-values from -4 to 4 in increments of .001
x = np.arange(-4, 4, 0.001)

#create range of y-values that correspond to normal pdf with mean=0 and sd=1 
y = norm.pdf(x,0,1)

#define plot 
fig, ax = plt.subplots(figsize=(9,6))
ax.plot(x,y)

#choose plot style and display the bell curve 
plt.style.use('fivethirtyeight')
plt.show()

Courbe en cloche en Python

Comment remplir une courbe en cloche en Python

Le code suivant illustre comment remplir la zone sous la courbe en cloche allant de -1 à 1 :

x = np.arange(-4, 4, 0.001)
y = norm.pdf(x,0,1)

fig, ax = plt.subplots(figsize=(9,6))
ax.plot(x,y)

#specify the region of the bell curve to fill in 
x_fill = np.arange(-1, 1, 0.001)
y_fill = norm.pdf(x_fill,0,1)
ax.fill_between(x_fill,y_fill,0, alpha=0.2, color='blue')

plt.style.use('fivethirtyeight')
plt.show()

Courbe en cloche avec zone remplie en Python

Notez que vous pouvez également styliser le graphique comme vous le souhaitez en utilisant les nombreuses options de style de matplotlib . Par exemple, vous pouvez utiliser un thème « lumière solaire » avec une ligne verte et un ombrage vert :

x = np.arange(-4, 4, 0.001)
y = norm.pdf(x,0,1)

fig, ax = plt.subplots(figsize=(9,6))
ax.plot(x,y, color='green')

#specify the region of the bell curve to fill in 
x_fill = np.arange(-1, 1, 0.001)
y_fill = norm.pdf(x_fill,0,1)
ax.fill_between(x_fill,y_fill,0, alpha=0.2, color='green')

plt.style.use('Solarize_Light2')
plt.show()

Courbe de distribution normale en Python avec matplotlib

Vous pouvez trouver le guide complet de référence des feuilles de style pour matplotlib ici .

Ressources additionnelles

Comment créer une courbe en cloche dans Excel

Ajouter un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *