我有一个 seaborn.lineplot()
,还有一个 RGB 值列表,例如 [26,201,55]
。
我不知道在 sns.lineplot
中可以设置哪个参数来按照我的意愿更改颜色。
这是我的错误代码:
sns.lineplot(x='Episode',y='Mean Reward',sizes=(.25,.25),hue='Agent', data=df[0], palette=[r_rl/255,g_rl/255,b_rl/255]))
我有一个 seaborn.lineplot()
,还有一个 RGB 值列表,例如 [26,201,55]
。
我不知道在 sns.lineplot
中可以设置哪个参数来按照我的意愿更改颜色。
这是我的错误代码:
sns.lineplot(x='Episode',y='Mean Reward',sizes=(.25,.25),hue='Agent', data=df[0], palette=[r_rl/255,g_rl/255,b_rl/255]))
有一个参数palette
用于定义颜色,palette
只是由三个值为0到1的tuples
定义的颜色列表。
如果你只有一种颜色,可以使用:
palette=[(r_rl/255, g_rl/255, b_rl/255)]
但是对于多种颜色:
rgb = [(66, 135, 245), (255, 25, 0)] # first blue, second red
colors = [tuple(t / 255 for t in x) for x in rgb]
然后使用:
sns.lineplot(
x="Episode",
y="Mean Reward",
sizes=(0.25, 0.25),
hue="Agent",
data=df[0],
palette=colors,
)
随机示例:
import seaborn as sns
import matplotlib.pyplot as plt
rgb = [(66, 135, 245), (255, 25, 0)]
colors = [tuple(t / 255 for t in x) for x in rgb]
sns.set()
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(
x="timepoint",
y="signal",
hue="event",
data=fmri,
palette=colors,
)