2017-11-16 6 views
0

해저를 사용하여 JointGrid 플롯을 작성합니다.해저의 한계 플롯 중 하나만에 대한 범례 설정

import seaborn as sns 
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
mydataset=pd.DataFrame(data=np.random.rand(50,2),columns=['a','b']) 
g = sns.JointGrid(x=mydataset['a'], y=mydataset['b']) 
g=g.plot_marginals(sns.distplot,color='black',kde=True,hist=False,rug=True,bins=20,label='X') 
g=g.plot_joint(plt.scatter,label='X')   


legend_properties = {'weight':'bold','size':8} 
legendMain=g.ax_joint.legend(prop=legend_properties,loc='upper right') 


legendSide=g.ax_marg_x.legend(prop=legend_properties,loc='upper right') 

난이 얻을 :

enter image description here

내가 수직 한계 플롯 (오른쪽의 하나) 내에서 전설 없애 좋아하지만 수평 여백의 하나를 유지하는 것 . 어떻게 달성할까요?


편집 : @ImportanceOfBeingErnest에서이 솔루션은 하나의 플롯을 위해 잘 작동합니다. 그러나 for 루프에서이를 반복하면 예상치 못한 일이 발생합니다. 나는 여전히 위 그림에서 전설을 얻었으며 이는 예상치 못한 결과입니다. 어떻게 제거합니까?

다음 코드 :

import seaborn as sns 
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
mydataset=pd.DataFrame(data=np.random.rand(50,2),columns=['a','b']) 
g = sns.JointGrid(x=mydataset['a'], y=mydataset['b']) 
LABEL_LIST=['x','Y','Z'] 
for n in range(0,3): 

    g=g.plot_marginals(sns.distplot,color='black',kde=True,hist=False,rug=True,bins=20,label=LABEL_LIST[n]) 
    g=g.plot_joint(plt.scatter,label=LABEL_LIST[n])   


    legend_properties = {'weight':'bold','size':8} 
    legendMain=g.ax_joint.legend(prop=legend_properties,loc='upper right') 


    legendSide=g.ax_marg_y.legend(labels=[LABEL_LIST[n]],prop=legend_properties,loc='upper right') 

가 있습니다 : 나는 오른쪽에있는 PLO의 마지막 범례 항목을 제거 할 필요가 BYT, 거의 완벽

enter image description here

.

+0

하면 [최소 완료하고 검증 가능한 예]를 만들 수 (https://stackoverflow.com/help/mcve)? – DavidG

+0

여백 안쪽에 무엇이 있을지 예상되거나 이상 할 수 있습니다. 따라서 문제의 [mcve]를 작성하고 전설에 제시 할 내용과 그 이유를 분명하게 기술하십시오. – ImportanceOfBeingErnest

+0

예 지금 막하고 있습니다. – ErroriSalvo

답변

1

여백에 아무 레이블도 지정하지 않고 위쪽 여백 축 내에 범례를 만들 때 레이블을 추가 할 수 있습니다.

import seaborn as sns 
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 

mydataset=pd.DataFrame(data=np.random.rand(50,2),columns=['a','b']) 
g = sns.JointGrid(x=mydataset['a'], y=mydataset['b']) 
g=g.plot_marginals(sns.distplot,color='black', 
        kde=True,hist=False,rug=True,bins=20) 
g=g.plot_joint(plt.scatter,label='X')   


legend_properties = {'weight':'bold','size':8} 
legendMain=g.ax_joint.legend(prop=legend_properties,loc='upper right') 


legendSide=g.ax_marg_x.legend(labels=["x"], 
           prop=legend_properties,loc='upper right') 

plt.show() 

enter image description here

용액

루프의 플롯에 대해 동일하다.

import seaborn as sns 
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 

mydataset=pd.DataFrame(data=np.random.rand(50,2),columns=['a','b']) 
g = sns.JointGrid(x=mydataset['a'], y=mydataset['b']) 
LABEL_LIST=['x','Y','Z'] 
for n in range(0,3): 
    g=g.plot_marginals(sns.distplot,color='black',kde=True,hist=False,rug=True,bins=20) 
    g=g.plot_joint(plt.scatter,label=LABEL_LIST[n])   

legend_properties = {'weight':'bold','size':8} 
legendMain=g.ax_joint.legend(prop=legend_properties,loc='upper right') 
legendSide=g.ax_marg_x.legend(labels=LABEL_LIST,prop=legend_properties,loc='upper right') 

plt.show() 

enter image description here

+0

답변이 정확하고 받아 들일 것입니다 ...하지만 – ErroriSalvo

+0

루프에서이 작업을하고 있는데,이 작업을 1 단일 축. 여전히 작동할까요? – ErroriSalvo

+0

죄송합니다. 질문을 수정했습니다 ... 나중에 답변을 수락 할 것이지만 추가 정보를 제공 할 수 있다면 ... – ErroriSalvo