Extract RGB or 6-digit code from the Seaborn palette

Seaborn has the ability to create beautiful color palettes. I want to use these palettes to generate colors that work well together on a map where countries are shaded according to some properties. The following code generates 8 shades of purple from light to dark. Note that you also need to specify the number of colors, so I cannot just use a fixed palette of certain colors.

import seaborn as sns num_shades = 8 sns.palplot(sns.cubehelix_palette(num_shades)) 

If I run the same, but in a list, for example:

 color_list = sns.cubehelix_palette(num_shades) 

You get:

 [[0.9312692223325372, 0.8201921796082118, 0.7971480974663592], ... 

These are clearly not the RGB values ​​that I need.

1) What format are these colors in? 2) How can I convert to RGB or 6-digit codes?

I searched for a long time and did not find the answers. I looked here at another documentation on the sea:

https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.set_color_codes.html

I can convert to 6 digit codes from RGB using:

Convert RGB color set to six-digit code in Python

but I stick with how to do this directly or through getting RGB values. Any help would be appreciated.

+8
python rgb seaborn
source share
2 answers

The values ​​you get are in percent of 255, the maximum value of RGB. Just multiply each triplet of values ​​by 255 (and round if you like) to get the RGB values.

 for color in color_list: for value in color: value *= 255 

Then save them in a new list to have a list of RGB values.

+4
source share

If by "6-digit code" you mean a hexadecimal code, you can also do:

 pal = sns.color_palette(...) pal.as_hex() 
+14
source share

All Articles