Seaborn: Specify an exact color

∥☆過路亽.° 提交于 2021-02-08 13:28:07

问题


You can specify a color for plots, but Seaborn will mute the color a bit during plotting. Is there a way to turn off this behavior?

Example:

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)

Histogram with muted color

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

What the color should look like

I have tried several ways of specifying the color and all available styles in Seaborn, but nothing has worked. I am using iPython notebook and Python 2.7.


回答1:


It is not using a muted color, its using an alpha/transparency value as part of the default.

Two answers referencing ways to modify matplotlib object transparency:

  • https://stackoverflow.com/a/4708018
  • https://stackoverflow.com/a/24549558



回答2:


seaborn.distplot allows you to pass different parameters for styling (*_kws). Each plot function has it's own parameters and are therefor prefixed by the name of the plot. Eg. histogram has hist_kws. [distplot Reference]

Because the histogram plot is located in matplotlib, we'd have to look at the keyword parameters we can pass. Like you already figured out, you can pass the 'alpha' keyword parameter to get rid of the transparancy of the lines. See reference for more arguments (kwargs section). [pyplot Reference]



来源:https://stackoverflow.com/questions/32992773/seaborn-specify-an-exact-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!