他の人と共有するためのFigureを準備する

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」
  • 印刷する人がいる場合は、インクの使用量を抑える
  • 白黒印刷の場合は、「グレースケール」スタイル {{5}} を使用
Matplotlib によるデータ可視化入門

自分に合ったスタイルの選択を練習しましょう!

Matplotlib によるデータ可視化入門

Preparing Video For Download...