[英]Change color of seaborn lineplot
You can change colors using palettes
.您可以使用palettes
更改 colors。 Referring to https://seaborn.pydata.org/tutorial/color_palettes.html , try:参考https://seaborn.pydata.org/tutorial/color_palettes.html ,尝试:
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
fmri = sns.load_dataset("fmri")
# Try playing with one set or another:
#sns.set_palette("husl")
sns.set_palette("PuBuGn_d")
ax = sns.lineplot(x="timepoint", y="signal", hue="event", data=fmri)
you'll get different line colors, like this你会得到不同的行 colors,就像这样
or this或这个
You can use colour inside lineplot() method, however this, far as I know, works only with Series.您可以在 lineplot() 方法中使用颜色,但据我所知,这仅适用于系列。 You can transform your data to Series with this this:您可以使用以下方法将数据转换为 Series:
data = pd.Series(another_data)
Then plot Your data然后 plot 你的数据
sns.lineplot(..., data=data, color='red')
Another way is to use pallets另一种方法是使用托盘
palette = sns.color_palette("mako_r", 6)
sns.lineplot(..., palette=palette, data=data)
More you can find in Seaborn lineplot reference: https://seaborn.pydata.org/generated/seaborn.lineplot.html Or here: https://stackoverflow.com/a/58432483/12366487您可以在 Seaborn lineplot 参考中找到更多信息: https://seaborn.pydata.org/generated/seaborn.lineplot.html或此处: https://stackoverflow.com/a/58432483/12366487
At least in version 0.11.2 of seaborn, the lineplot function ( http://seaborn.pydata.org/generated/seaborn.lineplot.html
) has a parameter called palette that allows changing the color map used for the hue.至少在 seaborn 的 0.11.2 版中,线图 function ( http://seaborn.pydata.org/generated/seaborn.lineplot.html
) 有一个名为调色板的参数,允许更改用于色调的颜色 map。
To check the available color maps you can refer to https://matplotlib.org/stable/tutorials/colors/colormaps.html
要检查可用的颜色图,您可以参考https://matplotlib.org/stable/tutorials/colors/colormaps.html
import seaborn as sns
import matplotlib.pyplot as plt
fmri = sns.load_dataset("fmri")
#sns.lineplot(x="timepoint", y="signal", hue="event", data=fmri, palette="tab10")
sns.lineplot(x="timepoint", y="signal", hue="event", data=fmri, palette="Accent")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.