Förbereda diagram för delning

Introduktion till datavisualisering med Matplotlib

Ariel Rokem

Data Scientist

Ändra diagramstil

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

Introduktion till datavisualisering med Matplotlib

Välja en stil

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

Introduktion till datavisualisering med Matplotlib

Tillbaka till standardstilen

plt.style.use("default")
Introduktion till datavisualisering med Matplotlib

Tillgängliga stilar

Introduktion till datavisualisering med Matplotlib

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

Introduktion till datavisualisering med Matplotlib

Seaborn-stilar

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

Introduktion till datavisualisering med Matplotlib

Riktlinjer för val av diagramstil

  • Mörka bakgrunder är ofta svårare att läsa
  • Om färg är viktigt, välj färgblindvänliga alternativ
    • "seaborn-colorblind" eller "tableau-colorblind10"
  • Om diagrammet ska skrivas ut, använd lite bläck
  • Vid utskrift i svartvitt, använd stilen "grayscale"
Introduktion till datavisualisering med Matplotlib

Öva på att välja rätt stil!

Introduktion till datavisualisering med Matplotlib

Preparing Video For Download...