スモール・マルチプル

Matplotlibで学ぶデータ可視化入門

Ariel Rokem

Data Scientist

データの追加

ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-PRCP-NORMAL"], 
        color='b')
ax.set_xlabel("Time (months)")
ax.set_ylabel("Precipitation (inches)")
plt.show()

Matplotlibで学ぶデータ可視化入門

さらにデータを追加

ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-PRCP-25PCTL"], 
        linestyle='--', color='b')
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-PRCP-75PCTL"], 
        linestyle='--', color=color)
plt.show()

Matplotlibで学ぶデータ可視化入門

さらにデータ

ax.plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-NORMAL"],
        color='r')
ax.plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-25PCTL"], 
        linestyle='--', color='r')
ax.plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-75PCTL"], 
        linestyle='--', color='r')
plt.show()
Matplotlibで学ぶデータ可視化入門

データが多すぎます!

Matplotlibで学ぶデータ可視化入門

plt.subplotsでスモール・マルチプル

fig, ax = plt.subplots()
fig, ax = plt.subplots(3, 2)

plt.show()

Matplotlibで学ぶデータ可視化入門

サブプロットにデータを追加

ax.shape
(3, 2)
ax[0, 0].plot(seattle_weather["MONTH"], 
              seattle_weather["MLY-PRCP-NORMAL"], 
              color='b')

plt.show()

Matplotlibで学ぶデータ可視化入門

データ付きサブプロット

fig, ax = plt.subplots(2, 1)

ax[0].plot(seattle_weather["MONTH"], seattle_weather["MLY-PRCP-NORMAL"], color='b') ax[0].plot(seattle_weather["MONTH"], seattle_weather["MLY-PRCP-25PCTL"], linestyle='--', color='b') ax[0].plot(seattle_weather["MONTH"], seattle_weather["MLY-PRCP-75PCTL"], linestyle='--', color='b')
ax[1].plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-NORMAL"], color='r') ax[1].plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-25PCTL"], linestyle='--', color='r') ax[1].plot(austin_weather["MONTH"], austin_weather["MLY-PRCP-75PCTL"], linestyle='--', color='r')
ax[0].set_ylabel("Precipitation (inches)") ax[1].set_ylabel("Precipitation (inches)")
ax[1].set_xlabel("Time (months)")
plt.show()
Matplotlibで学ぶデータ可視化入門

データ付きサブプロット

Matplotlibで学ぶデータ可視化入門

y軸範囲の共有

fig, ax = plt.subplots(2, 1, sharey=True)

Matplotlibで学ぶデータ可視化入門

サブプロット作成を練習しましょう!

Matplotlibで学ぶデータ可視化入門

Preparing Video For Download...