始める無料で始める

y 軸を共有するスモールマルチプル

スモールマルチプルを作成するときは、異なるプロットで y 軸のスケールをそろえて表示できると便利です。これは、sharey キーワードを True に設定することで指定できます。

この演習では、y 軸を共有する 2 つの Axes オブジェクトを持つ Figure を作成します。前と同様に、データは seattle_weatheraustin_weather の各 DataFrame に用意されています。

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

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

コースを見る

演習の手順

  • y 軸の範囲を共有する 2 つの Axes オブジェクトの配列を持つ Figure を作成します。
  • 上段の Axes に、Seattle の "MLY-PRCP-NORMAL" を青の実線でプロットします。
  • 上段の Axes に、Seattle の "MLY-PRCP-25PCTL""MLY-PRCP-75PCTL" を青の破線で追加します。
  • 下段の Axes に、Austin の "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()
コードを編集して実行