他者と共有するための図の準備

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...