2016-04-19 2 views
0

私は、同じプロット上に2つのデータセットをプロットしようとしていますが、マーカーは空の円です。私はこれを達成するために、下のマップ関数にfacecolor = 'none'を含めることを期待しますが、うまくいかないようです。私が以下で得ることができる最も近いのは、赤と青の暗い点の周りに赤い円を持つことです。facecolor = 'none'(空白の円)がseabornと.mapを使用していません

x1 = np.random.randn(50) 
y1 = np.random.randn(50)*100 
x2 = np.random.randn(50) 
y2 = np.random.randn(50)*100 

df1 = pd.DataFrame({'x1':x1, 'y1':y1}) 
df2 = pd.DataFrame({'x2':x2, 'y2':y2}) 

df = pd.concat([df1.rename(columns={'x1':'x','y1':'y'}) 
       .join(pd.Series(['df1']*len(df1), name='df')), 
       df2.rename(columns={'x2':'x','y2':'y'}) 
       .join(pd.Series(['df2']*len(df2), name='df'))], 
       ignore_index=True) 

pal = dict(df1="red", df2="blue") 
g = sns.FacetGrid(df, hue='df', palette=pal, size=5) 
g.map(plt.scatter, "x", "y", s=50, alpha=.7, linewidth=.5, facecolors = 'none', edgecolor="red") 
g.map(sns.regplot, "x", "y", ci=None, robust=1) 
g.add_legend() 

答えて

1

sns.regplotは、あなたがこのために必要なすべてのキーワードを通過していないが、あなたは明示的にscatterでそれを行うことができ、regplotの散乱をオフにして、伝説の再構築:

g.map(plt.scatter, "x", "y", s=50, alpha=.7, 
     linewidth=.5, 
     facecolors = 'none', 
     edgecolor=['red', 'blue']) 


g.map(sns.regplot, "x", "y", ci=None, robust=1, 
    scatter=False) 

markers = [plt.Line2D([0,0],[0,0], markeredgecolor=pal[key], 
         marker='o', markerfacecolor='none', 
         mew=0.3, 
         linestyle='') 
      for key in pal] 

plt.legend(markers, pal.keys(), numpoints=1) 
plt.show() 

enter image description here

関連する問題