Skip to content
Advertisement

Seaborn Color Palette not working appropiate with lineplot

I’m having a little trouble with customizing my colors for a lineplot. I want to show an ensemble of spectras with a sequential color palette. The argument “palette=”blues” works fine, but does not accept any appropriate color lists (like “Blues_d”), which do not include any bright colors.

This is a representative graph showing how my plot looks like

Below you can see the code I’m using.

color = (sns.dark_palette("purple"))
sns.set()

ax = sns.lineplot(x="Wavelength", y="Absorption", hue="t (min)", lw=1, data=df1, palette=color, legend="brief")

The problem is, that I get the following error:

ValueError: The palette list has the wrong number of colors.

So the question is: How can I use the lineplot function and using a sequential color palette of blues, reds, or whatever that do not include any bright colors?

I’m using pandas version 0.23.3, matplotlib version 2.2.2 and seaborn version 0.9.0

Advertisement

Answer

Since you mention the t (min) column in the hue option, you need to know the total number of unique values of the column.

Assume that there are 5 unique values in the column. You, thus, can set the number to the n_colors option of sns.color_palette:

ax = sns.lineplot(x="Wavelength", 
                  y="Absorption", 
                  hue="t (min)", 
                  lw=1, 
                  data=df1, 
                  palette=sns.color_palette('coolwarm', n_colors=5), 
                  legend="brief")
Advertisement