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

  • A Bokeh palette comprised of the Bokeh shutter logo colors

  • 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

Bokeh Palette#

Bokeh’s own palette, comprised of the shutter logo colors:

Bokeh

3
4
5
6
7
8

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)
See all values
Enumeration(Accent3, Accent4, Accent5, Accent6, Accent7, Accent8,

    Blues3, Blues4, Blues5, Blues6, Blues7, Blues8, Blues9, Blues256,

    Bokeh3, Bokeh4, Bokeh5, Bokeh6, Bokeh7, Bokeh8, BrBG3, BrBG4,

    BrBG5, BrBG6, BrBG7, BrBG8, BrBG9, BrBG10, BrBG11, BuGn3, BuGn4,

    BuGn5, BuGn6, BuGn7, BuGn8, BuGn9, BuPu3, BuPu4, BuPu5, BuPu6,

    BuPu7, BuPu8, BuPu9, Category10_3, Category10_4, Category10_5,

    Category10_6, Category10_7, Category10_8, Category10_9,

    Category10_10, Category20_3, Category20_4, Category20_5,

    Category20_6, Category20_7, Category20_8, Category20_9,

    Category20_10, Category20_11, Category20_12, Category20_13,

    Category20_14, Category20_15, Category20_16, Category20_17,

    Category20_18, Category20_19, Category20_20, Category20b3,

    Category20b4, Category20b5, Category20b6, Category20b7,

    Category20b8, Category20b9, Category20b10, Category20b11,

    Category20b12, Category20b13, Category20b14, Category20b15,

    Category20b16, Category20b17, Category20b18, Category20b19,

    Category20b20, Category20c3, Category20c4, Category20c5,

    Category20c6, Category20c7, Category20c8, Category20c9,

    Category20c10, Category20c11, Category20c12, Category20c13,

    Category20c14, Category20c15, Category20c16, Category20c17,

    Category20c18, Category20c19, Category20c20, Cividis3, Cividis4,

    Cividis5, Cividis6, Cividis7, Cividis8, Cividis9, Cividis10,

    Cividis11, Cividis256, Colorblind3, Colorblind4, Colorblind5,

    Colorblind6, Colorblind7, Colorblind8, Dark2_3, Dark2_4, Dark2_5,

    Dark2_6, Dark2_7, Dark2_8, GnBu3, GnBu4, GnBu5, GnBu6, GnBu7,

    GnBu8, GnBu9, Greens3, Greens4, Greens5, Greens6, Greens7,

    Greens8, Greens9, Greens256, Greys3, Greys4, Greys5, Greys6,

    Greys7, Greys8, Greys9, Greys256, Inferno3, Inferno4, Inferno5,

    Inferno6, Inferno7, Inferno8, Inferno9, Inferno10, Inferno11,

    Inferno256, Magma3, Magma4, Magma5, Magma6, Magma7, Magma8,

    Magma9, Magma10, Magma11, Magma256, OrRd3, OrRd4, OrRd5, OrRd6,

    OrRd7, OrRd8, OrRd9, Oranges3, Oranges4, Oranges5, Oranges6,

    Oranges7, Oranges8, Oranges9, Oranges256, PRGn3, PRGn4, PRGn5,

    PRGn6, PRGn7, PRGn8, PRGn9, PRGn10, PRGn11, Paired3, Paired4,

    Paired5, Paired6, Paired7, Paired8, Paired9, Paired10, Paired11,

    Paired12, Pastel1_3, Pastel1_4, Pastel1_5, Pastel1_6, Pastel1_7,

    Pastel1_8, Pastel1_9, Pastel2_3, Pastel2_4, Pastel2_5, Pastel2_6,

    Pastel2_7, Pastel2_8, PiYG3, PiYG4, PiYG5, PiYG6, PiYG7, PiYG8,

    PiYG9, PiYG10, PiYG11, Plasma3, Plasma4, Plasma5, Plasma6,

    Plasma7, Plasma8, Plasma9, Plasma10, Plasma11, Plasma256, PuBu3,

    PuBu4, PuBu5, PuBu6, PuBu7, PuBu8, PuBu9, PuBuGn3, PuBuGn4,

    PuBuGn5, PuBuGn6, PuBuGn7, PuBuGn8, PuBuGn9, PuOr3, PuOr4, PuOr5,

    PuOr6, PuOr7, PuOr8, PuOr9, PuOr10, PuOr11, PuRd3, PuRd4, PuRd5,

    PuRd6, PuRd7, PuRd8, PuRd9, Purples3, Purples4, Purples5,

    Purples6, Purples7, Purples8, Purples9, Purples256, RdBu3, RdBu4,

    RdBu5, RdBu6, RdBu7, RdBu8, RdBu9, RdBu10, RdBu11, RdGy3, RdGy4,

    RdGy5, RdGy6, RdGy7, RdGy8, RdGy9, RdGy10, RdGy11, RdPu3, RdPu4,

    RdPu5, RdPu6, RdPu7, RdPu8, RdPu9, RdYlBu3, RdYlBu4, RdYlBu5,

    RdYlBu6, RdYlBu7, RdYlBu8, RdYlBu9, RdYlBu10, RdYlBu11, RdYlGn3,

    RdYlGn4, RdYlGn5, RdYlGn6, RdYlGn7, RdYlGn8, RdYlGn9, RdYlGn10,

    RdYlGn11, Reds3, Reds4, Reds5, Reds6, Reds7, Reds8, Reds9,

    Reds256, Set1_3, Set1_4, Set1_5, Set1_6, Set1_7, Set1_8, Set1_9,

    Set2_3, Set2_4, Set2_5, Set2_6, Set2_7, Set2_8, Set3_3, Set3_4,

    Set3_5, Set3_6, Set3_7, Set3_8, Set3_9, Set3_10, Set3_11, Set3_12,

    Spectral3, Spectral4, Spectral5, Spectral6, Spectral7, Spectral8,

    Spectral9, Spectral10, Spectral11, Turbo3, Turbo4, Turbo5, Turbo6,

    Turbo7, Turbo8, Turbo9, Turbo10, Turbo11, Turbo256, Viridis3,

    Viridis4, Viridis5, Viridis6, Viridis7, Viridis8, Viridis9,

    Viridis10, Viridis11, Viridis256, YlGn3, YlGn4, YlGn5, YlGn6,

    YlGn7, YlGn8, YlGn9, YlGnBu3, YlGnBu4, YlGnBu5, YlGnBu6, YlGnBu7,

    YlGnBu8, YlGnBu9, YlOrBr3, YlOrBr4, YlOrBr5, YlOrBr6, YlOrBr7,

    YlOrBr8, YlOrBr9, YlOrRd3, YlOrRd4, YlOrRd5, 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 and palette2, take a combined n colors, and combine input palettes at the relative midpoint. palette1 and palette2 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, take n colors from it by dividing its length into n (approximately) evenly spaced indices.

Parameters
  • palette (seq[str]) – a sequence of hex RGB color strings

  • n (int) – the size of the output palette to generate

Returns

a sequence of hex RGB color strings

Return type

seq[str]

Raises

ValueError if n > len(palette)

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.