facecolor ='none'(空圈)在使用seaborn和.map时不起作用 [英] facecolor = 'none' (empty circles) not working using seaborn and .map

查看:24
本文介绍了facecolor ='none'(空圈)在使用seaborn和.map时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我试图在同一图上绘制 2 组数据,标记为空圆圈.我希望在下面的 map 函数中包含 facecolor = 'none' 来实现这一点,但它似乎不起作用.我能得到的最接近的是在红色和蓝色暗点周围有红色圆圈.

I have the following code where I am trying to plot 2 sets of data on the same plot, with the markers being empty circles. I would expect the inclusion of facecolor = 'none' in the map function below to accomplish this, but it does not seem to work. The closest I can get with the below is to have red circles around the red and blue dark dots.

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()

推荐答案

sns.regplot 不会通过所有您需要的关键字,但是您可以使用 scatter 明确,关闭 regplot 的分散,然后重建图例:

sns.regplot doesn't pass through all the keywords you need for this, but you can do it with scatter explicitly, turning off regplot's scatter, and then rebuilding the legend:

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()

这篇关于facecolor ='none'(空圈)在使用seaborn和.map时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆