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.
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
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")
No need to worry about the color count if you set your color palette as a color map by setting "as_cmap" argument to True in sns.color_palette:
ax = sns.lineplot(x="Wavelength",
y="Absorption",
hue="t (min)",
lw=1,
data=df1,
palette=sns.color_palette('coolwarm', as_cmap = True),
legend="brief")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With