简体   繁体   中英

Change color of seaborn lineplot

I have a seaborn lineplot:

plt.figure(figsize=(22,14))
sns.lineplot(x="Datum", y="Value", ci=None, hue='Type', data=df)
plt.show()

Which leads to the following output:

在此处输入图像描述

How can i change the linecolors? For me the difference is hard to see.

You can change colors using palettes . Referring to https://seaborn.pydata.org/tutorial/color_palettes.html , try:

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

在此处输入图像描述

or this

在此处输入图像描述

You can use colour inside lineplot() method, however this, far as I know, works only with Series. You can transform your data to Series with this this:

data = pd.Series(another_data)

Then plot Your data

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

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.

To check the available color maps you can refer to 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")

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