Seaborn offers a function called color_palette, which allows you to easily create new color_palettes for plots.
colors = ["#67E568","#257F27","#08420D","#FFF000","#FFB62B","#E56124","#E53E30","#7F2353","#F911FF","#9F8CA6"]
color_palette = sns.color_palette(colors)
I want to transform color_palette to a cmap, which I can use in matplotlib, but I don't see how I can do this.
Sadly just functions like "cubehelix_palette","light_palette",… have an "as_cmap" paramater. "color_palette" doesn't, unfortunately.
You have to convert a list of colors from seaborn palette to color map of matplolib (thx to @RafaelLopes for proposed changes):
Most seaborn methods to generate color palettes have an optional argument
as_cmap
which by default isFalse
. You can use to directly get a Matplotlib colormap:The first answer is somehow correct but way too long with a lot of unnecessary information. The correct and short answer is:
To convert any
sns.color_palette()
to a matplotlib compatible cmap you need two lines of codeJust an additional tip - if one wants a continuous colorbar/colormap, adding 256 as the number of colors required from Seaborn colorscheme helps a lot.