【问题标题】:How to change spot edge colors in seaborn scatter plots如何更改 seaborn 散点图中的点边缘颜色
【发布时间】:2018-10-23 23:23:29
【问题描述】:

我使用 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,但它似乎不起作用。有谁知道如何去除边缘颜色或将其更改为其他颜色?

【问题讨论】:

    标签: python seaborn scatter-plot


    【解决方案1】:

    edgecolors=None 替换为linewidth=0

    类似:

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

    【讨论】:

    • 非常感谢!这也回答了如何改变斑点的线宽。
    【解决方案2】:

    在 matplotlib 中,大多数参数都采用None,就像“使用默认值”一样。而在这里您不想使用默认值,而是不使用边缘颜色。这是通过"none" 完成的。

    sns.scatterplot(..., edgecolor="none")
    

    【讨论】:

      【解决方案3】:

      您可以通过传递 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='--',)
      

      输出 >>>

      我希望,我已经消除了你的疑问。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-07
        • 1970-01-01
        • 2016-03-04
        • 2010-11-26
        • 1970-01-01
        • 2015-05-28
        • 2020-10-10
        • 1970-01-01
        相关资源
        最近更新 更多