Seaborn的自定义调色板

时间:2020-01-11 14:29:52

标签: python python-3.x seaborn scatter-plot color-palette

我有一个散点图,应显示键长随温度的变化。我想给每个温度指定一种特定的颜色,但这似乎不起作用-绘图使用默认的seaborn调色板。有没有办法将温度映射到颜色,并让Seaborn使用它?

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

palette = ["#090364", "#091e75", "#093885", "#085396", "#086da6", 
           "#0888b7", "#08a2c7", "#07bdd8", "#07d7e8", "#07f2f9", 
           "#f9ac07", "#c77406", "#963b04", "#640303"]

sns.set_style("whitegrid")
sns.set_palette(palette)
plot = sns.scatterplot(df.loc[:,'length'], 
                       df.loc[:,'type'],
                       hue = df.loc[:,'temperature'],
                       legend = False, 
                       s = 200)

1 个答案:

答案 0 :(得分:3)

我知道了。您必须将多种颜色粘贴到调色板中:

sns.set_style("whitegrid")
plot = sns.scatterplot(df.loc[:,'length'], 
                       df.loc[:,'type'],
                       hue = df.loc[:,'temperature'],
                       palette=sns.color_palette(palette, 14),
                       legend = False, 
                       s = 200)