Příprava grafů ke sdílení

Introduction to Data Visualization with Matplotlib

Ariel Rokem

Data Scientist

Změna stylu grafu

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 to Data Visualization with Matplotlib

Výběr stylu

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 to Data Visualization with Matplotlib

Návrat na výchozí styl

plt.style.use("default")
Introduction to Data Visualization with Matplotlib

Dostupné styly

Introduction to Data Visualization with Matplotlib

Styl "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 to Data Visualization with Matplotlib

Styly 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 to Data Visualization with Matplotlib

Zásady výběru stylu grafu

  • Tmavá pozadí bývají méně přehledná
  • Je-li barva důležitá, zvažte možnosti pro barvoslepé
    • "seaborn-colorblind" nebo "tableau-colorblind10"
  • Má-li být graf tisknutý, používejte méně inkoustu
  • Pro tisk ve stupních šedi použijte styl "grayscale"
Introduction to Data Visualization with Matplotlib

Procvičte si výběr vhodného stylu!

Introduction to Data Visualization with Matplotlib

Preparing Video For Download...