Abbildungen vorbereiten, um sie mit anderen zu teilen

Einführung in die Datenvisualisierung mit Matplotlib

Ariel Rokem

Data Scientist

Diagrammstil ändern

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()

Einführung in die Datenvisualisierung mit Matplotlib

Stil auswählen

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()

Einführung in die Datenvisualisierung mit Matplotlib

Zurück zu den Standardeinstellungen

plt.style.use("default")
Einführung in die Datenvisualisierung mit Matplotlib

Die verfügbaren Stile

Einführung in die Datenvisualisierung mit Matplotlib

Der „bmh“-Stil

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()

Einführung in die Datenvisualisierung mit Matplotlib

Seaborn-Stile

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()

Einführung in die Datenvisualisierung mit Matplotlib

Tipps zur Auswahl des Diagrammstils

  • Dunkle Hintergründe sind meistens schlechter sichtbar
  • Wenn Farbe wichtig ist: Farbenblindheit berücksichtigen
    • „seaborn-colorblind“ oder „tableau-colorblind10“
  • Wenn Abbildung ausgedruckt werden soll: weniger Farbe verwenden
  • Wenn schwarz-weiß gedruckt werden soll: Stil „grayscale“ wählen
Einführung in die Datenvisualisierung mit Matplotlib

Zeit für ein paar Übungen!

Einführung in die Datenvisualisierung mit Matplotlib

Preparing Video For Download...