Color module#

Collection of color palettes and continuous color maps

copyright:

Copyright 2021- Matthias Cuntz, see AUTHORS.md for details.

license:

MIT License, see LICENSE for details.

Subpackages#

brewer_palettes

Color palettes from ColorBrewer2

ipcc_palettes

Color palettes from IPCC WG1

mathematica_palettes

Color palettes from Mathematica

ncl_palettes

Color palettes from the NCAR Command Language (NCL)

oregon_palettes

Color palettes from the University of Oregon

pyjams_palettes

pyjams own color palettes

sron2012_palettes

Color palettes of 2012 of Paul Tol at SRON - Netherlands Institute for Space Research

sron_palettes

Color palettes of Paul Tol at SRON - Netherlands Institute for Space Research

ufz_palettes

Colors from the guidelines of the Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany from 18.01.2007

color

Get, show, print color palettes

get_cmap(palette, ncol=0, offset=0, upper=1, reverse=False, grey=False, order=None, as_cmap=False)[source]#

Get colors of defined palettes or continuous colormaps

Parameters:
  • palette (str) – Name of color palette or continuous colormap

  • ncol (int, optional) – Number of desired colors. If 0, all colors defined by the specific palette will be returned. 256 colors will be chosen for continuous colormaps. If > 0, existing color palettes will be subsampled to ncol colors. ncol colors will be produced from continuous colormaps.

  • offset (float (0-1), optional) – Bottom fraction to exclude for subsample or continuous colormaps

  • upper (float (0-1), optional) – Upper most fraction to include for subsample or continuous colormaps

  • reverse (bool, optional) – Reverse colormap if True (default: False). This can also be achieved by adding ‘_r’ to the palette name. Palettes that end with ‘_r’ will not be reversed.

  • grey (bool, optional) – Return grey equivalent colors if True (default: False).

  • order (str, optional) – Order colors by ‘hue’, ‘saturation’, or ‘value’. This is done before reverse and grey (default: order from color sources).

  • as_cmap (bool, optional) – If True, returns matplotlib.colors.Colormap instead of list of RGB tuples

Returns:

List of RGB tuples or matplotlib.colors.Colormap

Return type:

list or matplotlib.colors.Colormap

Notes

get_cmap always returns a list of RGB tuples or a Matplotlib ListedColormap. You can use the ncol, offset, and upper keywords to subsample colormaps. To get smoothly-varying colormaps, you can use the method matplotlib.colors.LinearSegmentedColormap.from_list()

cols = get_cmap(‘sron_ylorbr’)

cmap = matplotlib.colors.LinearSegmentedColormap.from_list(cols)

You can get the color tuples from a LinearSegmentedColormap like this

colors = [ cmap(i) for i in range(cmap.N) ]

Examples

cols = get_cmap('mathematica_dark_rainbow_256', 15)
get_color(cname='')[source]#

Register new named colors with Matplotlib and return named color(s)

Registers the named colors given in ufz_palettes. Optionally returns the value(s) of the named color(s), which can be any color name known to Matplotlib.

Parameters:

cname (str or iterable of str, optional) – Colour name(s)

Examples

col1 = get_color('ufz:blue')
col2 = get_color('xkcd:blue')
cols = get_color(['blue', 'red'])
print_colors(collection='')[source]#

Print the known named colors

Parameters:

collection (str or list of strings, optional) – Name(s) of color collection(s). Known collections are ‘base’, ‘tableau’, ‘ufz’, ‘css’, and ‘xkcd’.

Returns:

Prints list of known named colors to console.

Return type:

None

Examples

print_colors()
print_palettes(collection='')[source]#

Print the known color palettes and continuous colormaps

Parameters:

collection (str or list of strings, optional) – Name(s) of color palette collection(s). Known collections are ‘pyjams’, ‘sron’, ‘sron2012’, ‘mathematica’, ‘oregon’, ‘ipcc’, ‘ncl’, ‘matplotlib’, and ‘brewer’.

Returns:

Prints list of known color palettes and continuous colormaps to console.

Return type:

None

Examples

print_palettes()
show_palettes(outfile='', collection='')[source]#

Show the known color palettes and continuous colormaps

Parameters:
  • outfile (str, optional) – Output file name. Output type will be determined from file suffix.

  • collection (str or list of strings, optional) – Name(s) of color palette collection(s). All palettes will be shown if collection is empty or ‘all’. Known collections are: ‘pyjams’, ‘sron’, ‘sron2012’, ‘mathematica’, ‘oregon’, ‘ipcc’, ‘ncl’, ‘matplotlib’, and ‘brewer’.

Returns:

Plots known color palettes and continuous colormaps in file or on plotting window.

Return type:

None

Examples

show_palettes(outfile='pyjams_cmaps.pdf',
              collection=['mathematica', 'matplotlib'])