2017-03-18 1 views
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에서 볼 수 , 당신은 두 번째

legend = Bind.legend(...) 
Bind.add_artist(legend) 
Bind.legend(...) 
를 작성하기 전에 축에 아티스트로 처음 전설을 추가 할 필요가