改变海底情节线的颜色 [英] Changing color of seaborn plot line

查看:79
本文介绍了改变海底情节线的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在seaborn中更改2d线的颜色。
我的绘图中有2条线,我想为它们分配不同的颜色。

I cant change color of a 2d line in seaborn. I have 2 lines in my plot and I want to assign different colors for both of them.

sns.set(style="whitegrid")
data = pd.DataFrame(result_prices, columns=['Size percentage increase'])
data2 = pd.DataFrame(result_sizes, columns=['Size percentage increase'])
sns_plot = sns.lineplot(data=data, color='red', linewidth=2.5)
sns_plot = sns.lineplot(data=data2, linewidth=2.5)
sns_plot.figure.savefig("size_percentage_increase.png")

但是 color ='red'不能更改颜色,为什么?

But color='red' does not change the color, why?

推荐答案

使用 color 参数仅适用于Series对象。由于您的数据框似乎只有一列,因此您可以将其创建为Series:

Using the color parameter only appears to work with Series objects. Since your dataframes seem to only be one column, you could create them as Series instead:

sns.set(style="whitegrid")
data = pd.Series(result_prices)
data2 = pd.Series(result_sizes)
sns_plot = sns.lineplot(data=data, color='red', linewidth=2.5)
sns_plot = sns.lineplot(data=data2, linewidth=2.5)
sns_plot.figure.savefig("size_percentage_increase.png")

文档就是一个例子

您也可以定义调色板

sns.set(style="whitegrid")
data = pd.DataFrame(result_prices, columns=['Size percentage increase'])
data2 = pd.DataFrame(result_sizes, columns=['Size percentage increase'])
sns_plot = sns.lineplot(data=data, palette=['red'], linewidth=2.5)
sns_plot = sns.lineplot(data=data2, linewidth=2.5)
sns_plot.figure.savefig("size_percentage_increase.png")

这篇关于改变海底情节线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆