Pregătirea figurilor pentru partajare

Introducere în vizualizarea datelor cu Matplotlib

Ariel Rokem

Data Scientist

Modificarea stilului graficului

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

Introducere în vizualizarea datelor cu Matplotlib

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

Introducere în vizualizarea datelor cu Matplotlib

Revenirea la stilul implicit

plt.style.use("default")
Introducere în vizualizarea datelor cu Matplotlib

Stilurile disponibile

Introducere în vizualizarea datelor cu Matplotlib

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

Introducere în vizualizarea datelor cu Matplotlib

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

Introducere în vizualizarea datelor cu Matplotlib

Ghid pentru alegerea stilului de reprezentare

  • Fondurile închise sunt de obicei mai puțin vizibile
  • Dacă culoarea este importantă, alegeți opțiuni prietenoase pentru daltonism
    • "seaborn-colorblind" sau "tableau-colorblind10"
  • Dacă figura va fi tipărită, utilizați mai puțin cerneală
  • Dacă va fi tipărită alb-negru, utilizați stilul "grayscale"
Introducere în vizualizarea datelor cu Matplotlib

Exersați alegerea stilului potrivit!

Introducere în vizualizarea datelor cu Matplotlib

Preparing Video For Download...