始める無料で始める

y軸を共有する小さな複数プロット

スモールマルチプルを作成する際は、異なるプロットが Y軸で同じスケールを使用して表示されるようにすることが望ましいです。これは、shareyキーワードをTrueに設定することで構成できます。

この演習では、y軸を共有する2つのAxesオブジェクトを持つFigureを作成します。従来通り、データはseattle_weatherおよびaustin_weatherのDataFramesで提供されます。

この演習はコースの一部です

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

コースを見る

演習の手順

  • y軸の範囲を共有する2つのAxesオブジェクトの配列を持つFigureを作成します。
  • 上部のAxesにシアトルの"MLY-PRCP-NORMAL"を青の実線でプロットします。
  • 上部のAxesにシアトルの"MLY-PRCP-25PCTL""MLY-PRCP-75PCTL"を青の破線で追加します。
  • 下部のAxesにオースティンの"MLY-PRCP-NORMAL"を赤の実線でプロットし、"MLY-PRCP-25PCTL""MLY-PRCP-75PCTL"を赤の破線でプロットします。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Create a figure and an array of axes: 2 rows, 1 column with shared y axis
fig, ax = plt.subplots(2, 1, sharey=True)

# Plot Seattle precipitation data in the top axes
____.plot(____, ____, color = ____)
____.plot(____, ____, color = ____, linestyle = ____)
____.plot(____, ____, color = ____, linestyle = ____)

# Plot Austin precipitation data in the bottom axes
____.plot(____, ____, color = ____)
____.plot(____, ____, color = ____, linestyle = ____)
____.plot(____, ____, color = ____, linestyle = ____)

plt.show()
コードを編集して実行