Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn: Specify an exact color

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.

like image 484
JoshuaA Avatar asked Oct 07 '15 12:10

JoshuaA


People also ask

How do I specify colors in seaborn?

Color codes can be set through the high-level seaborn style manager. Color codes can also be set through the function that sets the matplotlib color cycle. Map matplotlib color codes to the default seaborn palette. Use a different seaborn palette.

How do you change the color of a Lineplot in seaborn?

You can use the palette parameter to change the color of the lines for a multi-line line chart. Remember: in the section above about the hue parameter, I noted that you can create a multi-line lineplot by mapping a categorical variable to hue .

What is CMAP in seaborn?

cmapmatplotlib colormap name or object, or list of colors, optional. The mapping from data values to color space.

What is the function to give color to plot in seaborn?

Seaborn provides a function called color_palette(), which can be used to give colors to plots and adding more aesthetic value to it.


2 Answers

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
like image 163
ElizabethAB Avatar answered Nov 15 '22 09:11

ElizabethAB


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]

like image 35
Caramiriel Avatar answered Nov 15 '22 10:11

Caramiriel