2017-03-18 8 views
1

私は3つのプロットを1つの図にまとめ、多くの注目すべき情報が含まれています。私は最近、凡例のラベルに関連する線でラベルを付けるのではなく、凡例のラベルに色を付けることができました。2つの凡例ラベルを1つのプロット内の別の場所に配置する

enter image description here

しかし、私はプロットの一つ上の別の場所にラベルの別のセットを追加しようとすると、オリジナルは消えていするための効率的な方法です何

import matplotlib.pyplot as plt 
from matplotlib import gridspec 
import numpy as np 
import scipy as sp 
import matplotlib.ticker as tic 
from matplotlib.patches import Rectangle 

fig111 = plt.figure(figsize=(12,6)) 
gs = gridspec.GridSpec(1,3, width_ratios=[1,1,0.3]) 
Bind = fig111.add_subplot(gs[0]) 
BindD = fig111.add_subplot(gs[1], sharey=Bind) 
Hist = fig111.add_subplot(gs[2], sharey=BindD) 

... 
... 

empty = Rectangle((0, 0), 0, 0, alpha=0.0) 

l = Bind.legend([empty], ['Illustris-1'], 
     loc='upper left', frameon=False, handlelength=0, handletextpad=0) 
lD = BindD.legend([empty], ['Illustris-1-Dark'], 
     loc='upper left', frameon=False, handlelength=0, 
handletextpad=0) 

dw = Bind.legend([empty,empty,empty,empty], ['Carina', 'Sculptor', 'Ursa Minor', 'Leo I' ], 
     loc='center right', frameon=False, handlelength=0, handletextpad=0) 

l.get_texts()[0].set_color('slateblue') 
lD.get_texts()[0].set_color('crimson') 

dw.get_texts()[0].set_color('mediumspringgreen') 
dw.get_texts()[1].set_color('orchid') 
dw.get_texts()[2].set_color('c') 
dw.get_texts()[3].set_color('orange') 

gs.update(wspace=0) 
plt.setp([BindD.get_yticklabels() ,Hist.get_yticklabels()], visible=False) 

plt.show() 

enter image description here

両方のラベルが同じサブプロットにありますか?

答えて

1

matplotlibの伝説ガイドの章Multiple legends on the same axesに見られるように、2番目の1

legend = Bind.legend(...) 
Bind.add_artist(legend) 
Bind.legend(...) 
を作成する前に、軸にアーティストとしての最初の凡例を追加する必要があります
関連する問題