如何更改 seaborn 散点图中的点边缘颜色

How to change spot edge colors in seaborn scatter plots

我使用 seaborn 创建了一个散点图:

import seaborn as sns
sns.set(style="ticks", color_codes=True)
        
g=sns.scatterplot(x="length", y="coverage", data=df, hue = 'Products', edgecolors=None, alpha = 0.7)
g.set(yscale="log")
plt.xlabel("Length(bp)")
plt.ylabel("Coverage")
plt.legend(loc = 'lower right')
plt.savefig('ATN_plot.png',dpi = 600)

原始数据(部分):

contig  length  coverage    pathway Products
53  1230    2423    stigmatellin    Yes
58  1195    885 curacin Yes
65  1161    598 jamaicamide Yes
68  1159    8001    jamaicamide Yes
79  1113    1423    curacin Yes
105 1042    1106    stigmatellin    Yes
727 666 223 HSAF (heat stable antifungal factor)    Yes
787 655 37  curacin Yes
791 654 13  stigmatellin    Yes
798 652 49  stigmatellin    Yes
844 642 5774    jamaicamide Yes
89  1090    13  No  No
90  1089    10  No  No
91  1086    26  No  No
92  1080    16  No  No
93  1079    10  No  No
94  1079    13  No  No

最后的剧情是这样的:

我不喜欢斑点的白色边缘。图像的左下方大部分斑点堆积的部分看起来太白了。我已经在我的代码中包含 edgecolors=None 但它似乎不起作用。有谁知道如何去除边缘颜色或将其更改为其他颜色?

edgecolors=None替换为linewidth=0

类似于:

g=sns.scatterplot(x="length", y="coverage", data=df, hue = 'Products', 
                  linewidth=0, alpha = 0.7)

在 matplotlib 中,大多数参数采用 None 和 "use the default" 一样。而在这里您不想使用默认值,而是不想使用 edgecolor。这是通过 "none".

完成的
sns.scatterplot(..., edgecolor="none")

您可以通过传递 kwargs(关键字参数)来更改专色

kwargs  =   {'edgecolor':"r", # for edge color
             'linewidth':2.7, # line width of spot
             'linestyle':'--', # line style of spot
            }
sns.scatterplot(x = "tip", y = "total_bill", data = tips_df, hue = "sex", 
                size ="sex", sizes = (100, 300), palette = "nipy_spectral" ,**kwargs)

或者您可以直接将其作为参数传递,例如:

sns.scatterplot(x = "tip", y = "total_bill", data = tips_df, hue = "sex", 
                size ="sex", sizes = (100, 300), palette = "nipy_spectral",
                edgecolor='r',
                linewidth=2,
                linestyle='--',)

输出>>>

我希望,我已经解决了你的疑问。