简体   繁体   中英

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.

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")

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")
Palette = ["#090364", "#091e75"] #define your preference
sns.set_style("whitegrid")
sns.set_palette(Palette) #use the list defined in the function
plot = sns.countplot(df['Purchased']) #Enjoy ploting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM