Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Is there a way to map temperature to color, and make seaborn use it?

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)
like image 797
Anavae Avatar asked Jan 11 '20 14:01

Anavae


People also ask

How do I create a custom color palette?

On the Page Design tab, in the Schemes group, click the More arrow on the color schemes gallery. Click Create new color scheme. In the Create New Color Scheme dialog box, under New, click the arrow next to each color that you want to change, and then select a new color.

How do I change colors in seaborn?

You can customize the colors in your heatmap with the cmap parameter of the heatmap() function in seaborn.

What is seaborn palette?

The default color palette in seaborn is a qualitative palette with ten distinct hues: sns. color_palette() These colors have the same ordering as the default matplotlib color palette, "tab10" , but they are a bit less intense.


1 Answers

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)
like image 65
Anavae Avatar answered Oct 30 '22 12:10

Anavae