HTML color codes are another way to define a RGB color using an hexadecimal numeral system.
example : #2D85C9
<-> (48, 133, 201)
alpha
(canal alpha)plot_cmap("Dark2", 4)
plot_cmap("Blues", 8)
In matplotlib all palettes suffixed by _r
are reversed.
plot_cmap("Blues_r", 8)
plot_cmap("coolwarm", 9)
plot_cmap(plt.cm.summer, 6)
colormap
returns a rgba
color.
plt.cm.summer(X=42)
(0.16470588235294117, 0.58235294117647063, 0.40000000000000002, 1.0)
plt.cm.colormap.N
print("Max val = ", plt.cm.summer.N)
palette = plt.cm.summer(X=[1, 50, 100, 200], alpha=.6)
print(palette)
show_colors(palette)
Max val = 256 [[ 0.00392157 0.50196078 0.4 0.6 ] [ 0.19607843 0.59803922 0.4 0.6 ] [ 0.39215686 0.69607843 0.4 0.6 ] [ 0.78431373 0.89215686 0.4 0.6 ]]
Normalize
normalize = mpl.colors.Normalize(vmin=-5, vmax=5)
palette = plt.cm.summer(X=normalize([-4, -2, 0, 2, 4]), alpha=1)
print(palette)
show_colors(palette)
[[ 0.09803922 0.54901961 0.4 1. ] [ 0.29803922 0.64901961 0.4 1. ] [ 0.50196078 0.75098039 0.4 1. ] [ 0.70196078 0.85098039 0.4 1. ] [ 0.90196078 0.95098039 0.4 1. ]]
Colorlover provides function to set up a color palette
import colorlover as cl
cl.colorsys
: conversion between color modelscl.scales
: color palettecl.to_HTML
: help function to show the palettecl.scales
has to be used following :
cl.scales["number"]["type"]["name"]
where
number
is a number between 3 and 12 includedtype
is : div
, seq
or qual
name
is the palette nameAll palettes are not available for all combinations.
For example, this is divergent palettes with 4 colors. You have to use cl.to_html
to get an html version and HTML()
to ask the notebook to display the html code and show the palette.
HTML(cl.to_html(cl.scales["4"]["div"]))
Divergent color palette PuOr
with 4 colors :
cl.scales["4"]["div"]["PuOr"]
['rgb(230,97,1)', 'rgb(253,184,99)', 'rgb(178,171,210)', 'rgb(94,60,153)']
In order to use this palette with matplotlib you have to convert it in true RGB triplets.
cl.to_numeric(cl.scales["4"]["div"]["PuOr"])
[(230.0, 97.0, 1.0), (253.0, 184.0, 99.0), (178.0, 171.0, 210.0), (94.0, 60.0, 153.0)]
The documentation is really clear and provides a nice tutorial seaborn color palettes. The following juste provides simple exampl cases.
import seaborn as sns
seaborn provides several functions in order to build and show color palettes. For example, in order to show the current palette :
current_palette = sns.color_palette()
sns.palplot(current_palette)
sns.palplot(sns.color_palette("husl", 8))
sns.palplot(sns.light_palette("violet", 4))
sns.palplot(sns.diverging_palette(220, 20, n=5))
Germain