Comparaisons quantitatives : histogrammes

Introduction à la visualisation de données avec Matplotlib

Ariel Rokem

Data Scientist

Histogrammes

Introduction à la visualisation de données avec Matplotlib

Encore un diagramme à barres

fig, ax = plt.subplots()

ax.bar("Rowing", mens_rowing["Height"].mean())
ax.bar("Gymnastics", mens_gymnastics["Height"].mean())
ax.set_ylabel("Height (cm)") plt.show()

Introduction à la visualisation de données avec Matplotlib

Présentation des histogrammes

fig, ax = plt.subplots()

ax.hist(mens_rowing["Height"])
ax.hist(mens_gymnastics["Height"])
ax.set_xlabel("Height (cm)") ax.set_ylabel("# of observations") plt.show()

Introduction à la visualisation de données avec Matplotlib

Les étiquettes sont nécessaires

ax.hist(mens_rowing["Height"], label="Rowing")
ax.hist(mens_gymnastics["Height"], label="Gymnastics")
ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")

ax.legend() plt.show()

Introduction à la visualisation de données avec Matplotlib

Personnalisation des histogrammes : définition du nombre de classes

ax.hist(mens_rowing["Height"], label="Rowing", bins=5)
ax.hist(mens_gymnastics["Height"], label="Gymnastics", bins=5)
ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")
ax.legend()
plt.show()

Introduction à la visualisation de données avec Matplotlib

Personnalisation des histogrammes : définition des limites des classes

ax.hist(mens_rowing["Height"], label="Rowing",
        bins=[150, 160, 170, 180, 190, 200, 210])

ax.hist(mens_gymnastics["Height"], label="Gymnastics",
        bins=[150, 160, 170, 180, 190, 200, 210])

ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")
ax.legend()
plt.show()

Introduction à la visualisation de données avec Matplotlib

Personnalisation des histogrammes : transparence

ax.hist(mens_rowing["Height"], label="Rowing",
        bins=[150, 160, 170, 180, 190, 200, 210],
        histtype="step")

ax.hist(mens_gymnastics["Height"], label="Gymnastics",
        bins=[150, 160, 170, 180, 190, 200, 210],
        histtype="step")

ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")
ax.legend()
plt.show()
Introduction à la visualisation de données avec Matplotlib

Histogramme avec un paramètre histtype de type palier

Introduction à la visualisation de données avec Matplotlib

Créez votre propre histogramme !

Introduction à la visualisation de données avec Matplotlib

Preparing Video For Download...