【问题标题】:Seaborn: Specify an exact colorSeaborn:指定准确的颜色
【发布时间】:2016-01-04 17:12:30
【问题描述】:

您可以为绘图指定颜色,但 Seaborn 会在绘图过程中稍微减弱颜色。有没有办法关闭这种行为?

例子:

import matplotlib
import seaborn as sns
import numpy as np

# Create some data
np.random.seed(0)
x = np.random.randn(100)

# Set the Seaborn style
sns.set_style('white')

# Specify a color for plotting
current_palette = matplotlib.colors.hex2color('#86b92e')

# Make a plot
g = sns.distplot(x, color=current_palette)

# Show what the color should look like
sns.palplot(current_palette)

我尝试了几种在 Seaborn 中指定颜色和所有可用样式的方法,但没有任何效果。我正在使用 iPython 笔记本和 Python 2.7。

【问题讨论】:

标签: python matplotlib ipython-notebook seaborn


【解决方案1】:

seaborn.distplot 允许您为样式传递不同的参数 (*_kws)。每个绘图函数都有自己的参数,因此以绘图名称为前缀。例如。直方图有hist_kws。 [distplot Reference]

因为直方图位于 matplotlib 中,所以我们必须查看可以传递的关键字参数。就像您已经知道的那样,您可以传递 'alpha' 关键字参数来消除线条的透明度。有关更多参数,请参阅参考资料(kwargs 部分)。 [pyplot Reference]

【讨论】:

    【解决方案2】:

    它没有使用柔和的颜色,它使用 alpha/透明度值作为默认值的一部分。

    参考修改matplotlib对象透明度方法的两个答案:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      相关资源
      最近更新 更多