Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select a specific color from matplotlib colormaps?

import matplotlib as plt
import seaborn as sns
pallete = sns.color_palette("tab10", 3)

In python, this gives the first three colors from the tab10 colormaps. How can I use the other colors? For example, instead of using the first three colors of tab10, I want to use the 1st, 2nd and 4th one. Or, I want to use the 1st, 6th and 8th one. Is it possible? Thank you for your kind concern.

enter image description here

like image 376
Tanvir Alam Shifat Avatar asked Sep 15 '25 16:09

Tanvir Alam Shifat


1 Answers

Seaborn's palettes are represented as lists of rgb values. You can use these lists to create a new palette. For example:

import seaborn as sns

palette_tab10 = sns.color_palette("tab10", 10)
palette = sns.color_palette([palette_tab10[0], palette_tab10[1], palette_tab10[3]])
sns.palplot(palette_tab10)

seaborn palette tab10

sns.palplot(palette)

seaborn tab10 1st,2nd,4th

To obtain a matplotlib colormap, add as_cmap=True:

cmap = sns.color_palette([palette_tab10[0], palette_tab10[1], palette_tab10[3]], as_cmap=True)

Seaborn also allows to just provide a list of colors as the palette parameter, e.g.:

sns.palplot(['DeepSkyBlue', palette_tab10[3], 'Chartreuse'])

palette as list of colors

like image 74
JohanC Avatar answered Sep 17 '25 07:09

JohanC