更改seaborn线图的颜色

时间:2020-04-24 06:02:57

标签: python seaborn

我有一条线状图:

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

这将导致以下输出:

enter image description here

如何更改线条颜色?对我来说,区别很难看到。

2 个答案:

答案 0 :(得分:3)

您可以使用palettes更改颜色。参考Javadocs,请尝试:

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)

您将获得不同的线条颜色

https://seaborn.pydata.org/tutorial/color_palettes.html

或这个

enter image description here

答案 1 :(得分:2)

您可以在lineplot()方法中使用color,但是据我所知,它仅适用于Series。 您可以使用以下方法将数据转换为Series:

php artisan migrate:fresh

然后绘制数据

data = pd.Series(another_data)

另一种方法是使用托盘

sns.lineplot(..., data=data, color='red')

您可以在Seaborn线图参考中找到更多信息:https://seaborn.pydata.org/generated/seaborn.lineplot.html 或在这里: https://stackoverflow.com/a/58432483/12366487