简体   繁体   English

seaborn 中的自定义调色板

[英]Custom color palette in seaborn

I have a scatterplot that should show the changes in bond lengths depending on temperature.我有一个散点图,它应该显示键长随温度的变化。 I wanted to give each temperature a specific color, but it doesn't seem to work - plot uses the default seaborn palette.我想给每个温度一个特定的颜色,但它似乎不起作用 - plot 使用默认的 seaborn 调色板。 Is there a way to map temperature to color, and make seaborn use it?有没有办法将温度映射到颜色,并让 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)

I figured it out.我想到了。 You had to paste the number of colors into the palette:您必须将颜色数量粘贴到调色板中:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM