2016-09-07 38 views
0

我有一些問題想出如何強制matplotlib添加圖例我想要的地方。 enter image description hereMatplotlib全球傳奇很多subplots

enter image description here

我生成這個2以下腳本分頁情節:

n = 1 
trn = True 
for i in diff.keys(): 
    plt.subplot(8, 4, n) 
    plt.xlim([0, rounds + 1]) 
    plt.locator_params(axis='y', nbins=5) 
    if PEPTIDE_KD[i] == 1e-2: 
     plt.plot(x_cord, [x[0] for x in diff[i]], 'ro--', label='asd') 
     plt.plot(x_cord, [x[1] for x in diff[i]], 'rv--', label='bsd') 
    else: 
     plt.plot(x_cord, [x[0] for x in diff[i]], 'bo--', label='asd') 
     plt.plot(x_cord, [x[1] for x in diff[i]], 'bv--', label='csd') 
    plt.title(i) 
    n += 1 
    if n == 33 and trn: 
     n = 1 
     trn = False 
     plt.suptitle('Ligand energies') 
     plt.locator_params(axis='y', nbins=5) 
     plt.subplots_adjust(hspace=0.35) 
     plt.show() 

plt.legend(bbox_to_anchor=(-0.05, 1), loc=1) 
plt.locator_params(axis='y', nbins=5) 
plt.subplots_adjust(hspace=0.35) 
plt.show() 

但是我想放置圖例

目前,我有這個樣子的數字在第一個子區域的左側,或者在第一行的最後一個子區域的右側。

我可以用if line == 0 bla bla做到這一點,但問題是你可以在我附上的圖表中看到,例如最後一幅圖只包含藍色數據,因此只有藍色圖例會顯示。我想把完整的傳說(紅色和藍色)以及同一個地方。我甚至不知道事先將藍色和紅色的情節放在哪裏。

這可能嗎?

回答