我有以下代码,我试图在同一个图上绘制2组数据,标记为空圆圈。我希望在下面的map函数中包含facecolor ='none'来实现这一点,但它似乎不起作用。我可以得到的最接近的是红色和蓝色黑点周围的红色圆圈。
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()
答案 0 :(得分: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()