问题
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)
# Show what the color should look like
sns.palplot(current_palette)
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