【问题标题】:Colors in seaborn vary depending on type of graph?seaborn 中的颜色因图形类型而异?
【发布时间】:2021-03-28 18:17:32
【问题描述】:

我需要在seaborn中定义一个pallet,如下图:

1

这很好用,因为调用时颜色很好: 2

但是,当使用不同类型的绘图调用相同的颜色时,结果会大不相同:3

这里发生了什么? seaborn 是否根据情节类型应用某种色调?

谢谢!

【问题讨论】:

标签: python seaborn color-palette


【解决方案1】:

看起来sns.histplot 绘制的直方图条是部分透明绘制的,导致颜色变浅。根据the distplot documentation,您可以通过hist_kws 参数提供alpha 关键字来覆盖直方图的不透明度:

sns.distplot(…, hist_kws={'alpha': 1})

请注意,如果您只是绘制直方图而不使用 seaborn 的核密度估计或地毯特征,您也可以直接调用 ax.hist from matplotlib,例如:

ax[0].plot(total_nofda["eccentricConnectivityIndexDescriptor"], bins=100, color=c('blue'))

编辑添加:确实,seaborn 的 distplot 自动将直方图的 alpha(不透明度值)设置为 0.4。来自seaborn's GitHub:

if hist:
    # …
    hist_kws.setdefault("alpha", 0.4)
    # …

【讨论】:

猜你喜欢
  • 2018-08-28
  • 2023-03-29
  • 2022-01-11
  • 2020-01-30
  • 2018-09-20
  • 2021-08-18
  • 1970-01-01
  • 2020-06-23
相关资源
最近更新 更多