我有一個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]))
uj5u.com熱心網友回復:
有一個palette用于定義顏色的引數,palette只是一個定義為tuples0 到 1 之間的 3 個值的顏色串列。
如果您只有一種顏色,則可以使用:
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,
)
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/376615.html
標籤:Python matplotlib 海生
