Подготовка графиков для публикации

Введение в визуализацию данных с 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...