2017-11-16 7 views
0

海底を使ってJointGridプロットを作成しています。海底の境界線の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,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

私は垂直限界プロット(右側1)内の伝説を取り除くしたいが、水平方向のマージンのための1を続けるだろう。 これを達成する方法は?


EDIT:@ImportanceOfBeingErnestのソリューションは、1つのプロットで問題なく機能します。しかし、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

私はこの作業をループで行います。単一軸。これはまだ動作しますか? – ErroriSalvo

+0

申し訳ありませんが、私は質問を編集しました...後で私はとにかくあなたの答えを受け入れるだろうが、それは余分な外観を与えることができる場合... – ErroriSalvo

関連する問題