Підготовка фігур для спільного використання з іншими

Вступ до візуалізації даних з Matplotlib

Ariel Rokem

Data Scientist

Зміна стилю графіка

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

Вступ до візуалізації даних з Matplotlib

Вибір стилю

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

Вступ до візуалізації даних з Matplotlib

Повернення до стандартного

plt.style.use("default")
Вступ до візуалізації даних з Matplotlib

Доступні стилі

Вступ до візуалізації даних з Matplotlib

Стиль "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()

Вступ до візуалізації даних з Matplotlib

Стилі 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()

Вступ до візуалізації даних з Matplotlib

Поради щодо вибору стилю побудови

  • Темні фони зазвичай менш помітні
  • Якщо колір важливий, оберіть варіанти, зручні для людей із дальтонізмом
    • "seaborn-colorblind" або "tableau-colorblind10"
  • Якщо фігуру можуть друкувати, економте чорнило
  • Для чорно-білого друку використайте стиль "grayscale"
Вступ до візуалізації даних з Matplotlib

Попрактикуймось у виборі стилю!

Вступ до візуалізації даних з Matplotlib

Preparing Video For Download...