Préparer vos figures à partager

Introduction à la visualisation de données avec Matplotlib

Ariel Rokem

Data Scientist

Changer le style du tracé

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"])
ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"])
ax.set_xlabel("Time (months)")
ax.set_ylabel("Average temperature (Fahrenheit degrees)")
plt.show()

Introduction à la visualisation de données avec Matplotlib

Choisir un style

plt.style.use("ggplot")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Introduction à la visualisation de données avec Matplotlib

Revenir au style par défaut

plt.style.use("default")
Introduction à la visualisation de données avec Matplotlib

Styles offerts

Introduction à la visualisation de données avec Matplotlib

Le style « bmh »

plt.style.use("bmh")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Introduction à la visualisation de données avec Matplotlib

Styles Seaborn

plt.style.use("seaborn-colorblind")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Introduction à la visualisation de données avec Matplotlib

Conseils pour choisir un style de tracé

  • Les fonds sombres sont souvent moins lisibles
  • Si la couleur est clé, pensez aux options adaptées au daltonisme
    • « seaborn-colorblind » ou « tableau-colorblind10 »
  • Si la figure risque d'être imprimée, utilisez moins d'encre
  • Si l'impression est en noir et blanc, choisissez le style « grayscale »
Introduction à la visualisation de données avec Matplotlib

Passons à la pratique !

Introduction à la visualisation de données avec Matplotlib

Preparing Video For Download...