[英]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.参数 "palette="blues" 工作正常,但不接受任何适当的颜色列表(如 "Blues_d"),其中不包括任何亮色。
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")
Since you mention the t (min)
column in the hue
option, you need to know the total number of unique values of the column.由于您在hue
选项中提到了t (min)
列,因此您需要知道该列的唯一值的总数。
Assume that there are 5 unique values in the column.假设列中有 5 个唯一值。 You, thus, can set the number to the n_colors
option of sns.color_palette
:你,因此,可以设置成数n_colors
的选项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:如果您通过在 sns.color_palette 中将“as_cmap”参数设置为 True 将调色板设置为颜色图,则无需担心颜色计数:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.