bokeh.palettes¶
Provide a collection of palettes for color mapping.
In the context of Bokeh, a palette is a simple plain Python list of (hex) RGB color
strings. For example the Blues8
palette which looks like
is defined as:
('#084594', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#deebf7', '#f7fbff')
This module contains the following sets of palettes:
All ColorBrewer palettes
Categorical D3 palettes
The Matplotlib palettes Magma, Inferno, Plasma, and Viridis
Palettes designed for color-deficient usability
Additionally, you can also use any of the 256-color perceptually uniform Bokeh palettes from the external colorcet package, if it is installed.
Every pre-built palette is available as a module attributes, e.g.
bokeh.palettes.YlGn3
or bokeh.palettes.Viridis256
. The name of each
pre-built palette can be found in the __palettes__
module attribute.
There are also functions such as magma()
and
viridis()
that can generate lists of colors of
arbitrary size from special larger palettes.
The Brewer palettes are also collected and grouped by name in a
brewer
dictionary, e.g.: brewer['Spectral'][6]
. Similarly there are
attributes d3
, mpl
, and colorblind
that have dictionaries
corresponding to the those groups of palettes.
Finally, all palettes are collected in the all_palettes
palettes
module attribute, and the “small” palettes (i.e. excluding the ones with 256
colors) are collected and in a small_palettes
attribute.
Built-in Palettes¶
Matplotlib Palettes¶
Bokeh includes the Matplotlib palettes Magma, Inferno, Plasma, Viridis, and Cividis. This section shows the pre-defined small palettes in this group. There are also large 256-color versions of these palettes, shown below in the Large Palettes section.
Cividis |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
Inferno |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
Magma |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
Plasma |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
Viridis |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
D3 Palettes¶
Bokeh includes the categorical palettes from D3, which are shown below:
Category10 |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
3 | ||||||||||
4 | ||||||||||
5 | ||||||||||
6 | ||||||||||
7 | ||||||||||
8 | ||||||||||
9 | ||||||||||
10 |
Category20 |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3 | ||||||||||||||||||||
4 | ||||||||||||||||||||
5 | ||||||||||||||||||||
6 | ||||||||||||||||||||
7 | ||||||||||||||||||||
8 | ||||||||||||||||||||
9 | ||||||||||||||||||||
10 | ||||||||||||||||||||
11 | ||||||||||||||||||||
12 | ||||||||||||||||||||
13 | ||||||||||||||||||||
14 | ||||||||||||||||||||
15 | ||||||||||||||||||||
16 | ||||||||||||||||||||
17 | ||||||||||||||||||||
18 | ||||||||||||||||||||
19 | ||||||||||||||||||||
20 |
Category20b |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3 | ||||||||||||||||||||
4 | ||||||||||||||||||||
5 | ||||||||||||||||||||
6 | ||||||||||||||||||||
7 | ||||||||||||||||||||
8 | ||||||||||||||||||||
9 | ||||||||||||||||||||
10 | ||||||||||||||||||||
11 | ||||||||||||||||||||
12 | ||||||||||||||||||||
13 | ||||||||||||||||||||
14 | ||||||||||||||||||||
15 | ||||||||||||||||||||
16 | ||||||||||||||||||||
17 | ||||||||||||||||||||
18 | ||||||||||||||||||||
19 | ||||||||||||||||||||
20 |
Category20c |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3 | ||||||||||||||||||||
4 | ||||||||||||||||||||
5 | ||||||||||||||||||||
6 | ||||||||||||||||||||
7 | ||||||||||||||||||||
8 | ||||||||||||||||||||
9 | ||||||||||||||||||||
10 | ||||||||||||||||||||
11 | ||||||||||||||||||||
12 | ||||||||||||||||||||
13 | ||||||||||||||||||||
14 | ||||||||||||||||||||
15 | ||||||||||||||||||||
16 | ||||||||||||||||||||
17 | ||||||||||||||||||||
18 | ||||||||||||||||||||
19 | ||||||||||||||||||||
20 |
Brewer Palettes¶
Bokeh includes all the ColorBrewer palettes, shown below:
Accent |
||||||||
---|---|---|---|---|---|---|---|---|
3 | ||||||||
4 | ||||||||
5 | ||||||||
6 | ||||||||
7 | ||||||||
8 |
Blues |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
BrBG |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
BuGn |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
BuPu |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Dark2 |
||||||||
---|---|---|---|---|---|---|---|---|
3 | ||||||||
4 | ||||||||
5 | ||||||||
6 | ||||||||
7 | ||||||||
8 |
GnBu |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Greens |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Greys |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
OrRd |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Oranges |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
PRGn |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
Paired |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
3 | ||||||||||||
4 | ||||||||||||
5 | ||||||||||||
6 | ||||||||||||
7 | ||||||||||||
8 | ||||||||||||
9 | ||||||||||||
10 | ||||||||||||
11 | ||||||||||||
12 |
Pastel1 |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Pastel2 |
||||||||
---|---|---|---|---|---|---|---|---|
3 | ||||||||
4 | ||||||||
5 | ||||||||
6 | ||||||||
7 | ||||||||
8 |
PiYG |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
PuBu |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
PuBuGn |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
PuOr |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
PuRd |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Purples |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
RdBu |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
RdGy |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
RdPu |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
RdYlBu |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
RdYlGn |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
Reds |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Set1 |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Set2 |
||||||||
---|---|---|---|---|---|---|---|---|
3 | ||||||||
4 | ||||||||
5 | ||||||||
6 | ||||||||
7 | ||||||||
8 |
Set3 |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
3 | ||||||||||||
4 | ||||||||||||
5 | ||||||||||||
6 | ||||||||||||
7 | ||||||||||||
8 | ||||||||||||
9 | ||||||||||||
10 | ||||||||||||
11 | ||||||||||||
12 |
Spectral |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | |||||||||||
4 | |||||||||||
5 | |||||||||||
6 | |||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 |
YlGn |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
YlGnBu |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
YlOrBr |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
YlOrRd |
|||||||||
---|---|---|---|---|---|---|---|---|---|
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 |
Usability Palettes¶
Bokeh includes some palettes that are useful for addressing color deficiencies. These are shown below.
Colorblind |
||||||||
---|---|---|---|---|---|---|---|---|
3 | ||||||||
4 | ||||||||
5 | ||||||||
6 | ||||||||
7 | ||||||||
8 |
Large Palettes¶
In addition to all the palettes shown above, which are available in the
small_palettes
attribute, the bokeh.palettes
module also has some
larger palettes with 256 colors. These are shown below:
- Greys256
(brewer)
- Inferno256
(mpl)
- Magma256
(mpl)
- Plasma256
(mpl)
- Viridis256
(mpl)
- Cividis256
(mpl)
- Turbo256
(mpl)
Many other 256-color perceptually uniform palettes are available in the external colorcet package.
Other Attributes¶
In addition to all the palettes described in the section above, there are the
following notable attributes in the bokeh.palettes
module:
-
__palettes__
¶ An alphabetical list of the names of all individual palettes in this module.
For example, the first eight palette names are:
>>> bp.__palettes__[:8] ('Accent3', 'Accent4', 'Accent5', 'Accent6', 'Accent7', 'Accent8', 'Blues3', 'Blues4')
Note
The full list of all palettes is also available as an enumeration from
bokeh.core.enums
:-
Palette
= Enumeration(Accent3, Accent4, Accent5, A .... Rd5, YlOrRd6, YlOrRd7, YlOrRd8, YlOrRd9)
-
-
all_palettes
¶ All built-in palette groups. This dictionary is indexed with a palette name to obtain a complete group of palettes, e.g.
Viridis
, and then further indexed with an integer to select a palette of a specific size from the group:>> all_palettes['Viridis'][4] ('#440154', '#30678D', '#35B778', '#FDE724')
The resulting palette looks like:
-
brewer
¶ Palette groups included from ColorBrewer. This dictionary is indexed with a palette name to obtain a complete group of palettes, e.g.
YlGnBu
, and then further indexed with an integer to select a palette of a specific size from the group:>> brewer['YlGnBu'][4] ('#225ea8', '#41b6c4', '#a1dab4', '#ffffcc')
The resulting palette looks like:
-
d3
¶ Categorical palette groups included from D3. This dictionary is indexed with a palette name to obtain a complete group of palettes, e.g.
Category20b
, and then further indexed with an integer to select a palette of a specific size from the group:>> d3['Category20b'][4] ('#393b79', '#5254a3', '#6b6ecf', '#9c9ede')
The resulting palette looks like:
The names of the D3 palette groups are:
Category10
,Category20
,Category20b
,Category20c
-
mpl
¶ Palette groups included from Matplotlib. This dictionary is indexed with a palette name to obtain a complete group of palettes, e.g.
Plasma
, and then further indexed with an integer to select a palette of a specific size from the group:>> mpl['Plasma'][4] ('#440154', '#30678D', '#35B778', '#FDE724')
The resulting palette looks like:
The names of the MPL palette groups are:
Inferno
,Magma
Plasma
,Viridis
-
small_palettes
¶ All palette groups, excluding 256-length palettes. This dictionary is indexed with a palette name to obtain a complete group of palettes, e.g.
Viridis
, and then further indexed with an integer to select a palette of a specific size from the group:>> small_palettes['Viridis'][4] ('#440154', '#30678D', '#35B778', '#FDE724')
The resulting palette looks like:
Functions¶
The bokeh.palettes
module also has several functions that can be used
to generate palettes of arbitrary size.
-
cividis
(n)[source]¶ Generate a palette of colors or from the Cividis palette.
The full Cividis palette that serves as input for deriving new palettes has 256 colors, and looks like:
- Parameters
n (int) – size of the palette to generate
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the base palette length of 256 –
Examples:
>>> cividis(6) ('#00204C', '#31446B', '#666870', '#958F78', '#CAB969', '#FFE945')
The resulting palette looks like:
-
diverging_palette
(palette1, palette2, n, midpoint)[source]¶ Generate a new palette by combining exactly two input palettes.
Given an input
palette1
andpalette2
, take a combinedn
colors, and combine input palettes at the relativemidpoint
.palette1
andpalette2
are meant to be sequential palettes that proceed left to right from perceptually dark to light colors. In that case the returned palette is comprised of the input palettes connected at perceptually light ends. Palettes are combined by piecewise linear interpolation.- Parameters
palette1 (seq[str]) – A sequence of hex RGB color strings for the first palette
palette2 (seq[str]) – A sequence of hex RGB color strings for the second palette
n (int) – The size of the output palette to generate
midpoint (float, optional) – Relative position in the returned palette where input palettes are connected (default: 0.5)
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the possible combined length the input palettes –
-
gray
(n)[source]¶ Generate a palette of colors or from the Greys palette.
The full Greys palette that serves as input for deriving new palettes has 256 colors, and looks like:
- Parameters
n (int) – size of the palette to generate
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the base palette length of 256 –
Examples:
>>> gray(6) ('#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff')
The resulting palette looks like:
Note
This function also has the alternate spelling
grey
-
grey
(n)[source]¶ Generate a palette of colors or from the Greys palette.
The full Greys palette that serves as input for deriving new palettes has 256 colors, and looks like:
- Parameters
n (int) – size of the palette to generate
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the base palette length of 256 –
Examples:
>>> grey(6) ('#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff')
The resulting palette looks like:
Note
This function also has the alternate spelling
gray
-
inferno
(n)[source]¶ Generate a palette of colors or from the Inferno palette.
The full Inferno palette that serves as input for deriving new palettes has 256 colors, and looks like:
- Parameters
n (int) – size of the palette to generate
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the base palette length of 256 –
Examples:
>>> inferno(6) ('#000003', '#410967', '#932567', '#DC5039', '#FBA40A', '#FCFEA4')
The resulting palette looks like:
-
linear_palette
(palette, n)[source]¶ Generate a new palette as a subset of a given palette.
Given an input
palette
, taken
colors from it by dividing its length inton
(approximately) evenly spaced indices.
-
magma
(n)[source]¶ Generate a palette of colors or from the Magma palette.
The full Magma palette that serves as input for deriving new palettes has 256 colors, and looks like:
- Parameters
n (int) – size of the palette to generate
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the base palette length of 256 –
Examples:
>>> magma(6) ('#000003', '#3B0F6F', '#8C2980', '#DD4968', '#FD9F6C', '#FBFCBF')
The resulting palette looks like:
-
viridis
(n)[source]¶ Generate a palette of colors or from the Viridis palette.
The full Viridis palette that serves as input for deriving new palettes has 256 colors, and looks like:
- Parameters
n (int) – size of the palette to generate
- Returns
a sequence of hex RGB color strings
- Return type
seq[str]
- Raises
ValueError if n is greater than the base palette length of 256 –
Examples:
>>> viridis(6) ('#440154', '#404387', '#29788E', '#22A784', '#79D151', '#FDE724')
The resulting palette looks like:
Licenses¶
The respective licenses for all the palettes included in Bokeh are viewable as a comment at the top of the bokeh/palettes.py source file.