Figure内のすべてのサブプロットをオーバーレイすることができる凡例を作成します。私がそのframealpha=1.0
を設定した場合、それはそのサブプロット上のものをカバーしますが、私は他のサブプロットのデータの「上に」置く必要があります。伝説の後ろを通るためには赤い線が必要です。 '上'で私はzの次元ではなく、そのyの位置について話しています。ここでmatplotlib:凡例を他のサブプロットの上に表示します。
は一例です:
import matplotlib.pyplot as plt
import numpy as np
x1 = np.random.rand(25)
y1 = np.random.rand(25)
x2 = np.random.rand(25)
y2 = np.random.rand(25)
f, axes = plt.subplots(1,2)
axes[0].plot(x1,y1,'b-',label='data 1 blah blah blah this is a wide legend that should sit top of BOTH subplots')
axes[1].plot(x2,y2,'r-')
axes[0].axis('off')
axes[1].axis('off')
leg = axes[0].legend(bbox_to_anchor=(0.5, .8), loc=2, fontsize=8, frameon=True, framealpha = 1.0)
rect = leg.get_frame()
rect.set_facecolor([0.9,0.9,0.9])
leg.set_zorder(100)
plt.show()
THANKS!
「上に」とは、例では赤い線の上に凡例があることを意味します。 zorderは他のものの上に横たわっていきたいものです。私は明確にするために私の質問を編集しました。 – NPMitchell
申し訳ありませんが、私は質問の冒頭で誤解していました。もっと明確な質問に感謝します。今私は、すべてのサブプロットの上に伝説を持つというあなたの具体的な質問に答える答えを変更しました。 – albertoql