API#

Colorsets#

tol_colors.colorsets#

Mapping of colorsets.

class tol_colors.ColorsetMapping#

Bases: dict[str, NamedTuple]

Special mapping replacing hyphens by underscores when retrieving an item.

tol_colors.set_default_colors(cset: str = 'bright', fname: str | None = None, dry: bool = False)#

Modify matplotlibrc to set default colors to those of one of the colorsets.

This will modify the colors used autmotically by matplotlib. This function will add a new line in a matplotlibrc file or stylesheet for the property “axes.prop_cycle”. If a line setting a color cycler already exist in the file, it will be overwritten.

This function can run without modifying the file and simply show the line to add by setting the dry parameter to True.

Parameters:
  • cset – Name of the colorset to set as new default. Default is “bright”.

  • fname

    Name of the file to modify. It can be a matplotlibrc or stylesheet file (see the matplotlib documentation on Customizing Matplotlib). If left to None, it will default to:

    • $MPLCONFIGDIR if set, else

    • On Unix/Linux: $XDG_CONFIG_HOME/matplotlib/matplotlibrc if set, else $HOME/.config/matplotlib/matplotlibrc

    • On other platforms $HOME/.matplotlib/matplotlibrc

    It will create the file and leading directories if necessary.

  • dry – If set to True, the function will only print the new configuration line to stdout and will not modify any file. You can then copy-paste the line manually.

tol_colors.bright: Bright#
class tol_colors.Bright(blue, red, green, yellow, cyan, purple, grey)#
tol_colors.vibrant: Vibrant#
class tol_colors.Vibrant(orange, blue, cyan, magenta, red, teal, grey)#
tol_colors.muted: Muted#
class tol_colors.Muted(rose, indigo, sand, green, cyan, wine, teal, olive, purple, pale_grey)#
tol_colors.high_contrast: HighContrast#
class tol_colors.HighContrast(black, blue, red, yellow, white)#
tol_colors.medium_contrast: MediumContrast#
class tol_colors.MediumContrast(white, light_blue, dark_blue, light_yellow, dark_yellow, light_red, dark_red, black)#
tol_colors.pale: Pale#
class tol_colors.Pale(pale_blue, pale_red, pale_green, pale_yellow, pale_cyan, pale_grey)#
tol_colors.dark: Dark#
class tol_colors.Dark(dark_blue, dark_red, dark_green, dark_yellow, dark_cyan, dark_grey)#
tol_colors.light: Light#
class tol_colors.Light(light_blue, orange, light_yellow, pink, light_cyan, mint, pear, olive, pale_grey)#
tol_colors.land_cover: LandCover#
class tol_colors.LandCover(water, evergreen_needleleaf_forest, evergreen_broadleaf_forest, deciduous_needleleaf_forest, deciduous_broadleaf_forest, mixed_forest, woodland, wooded_grassland, closed_shrubland, open_shrubland, grassland, cropland, bare_ground, urban_and_built_up)#

Colormaps#

tol_colors.colormaps#

Mapping of colormaps. Returns copies.

Sunset#

tol_colors.sunset: LinearSegmentedColormap#
tol_colors.sunset_r: LinearSegmentedColormap#
tol_colors.sunset_discrete: ListedColormap#
tol_colors.sunset_discrete_r: ListedColormap#

BuRd#

tol_colors.BuRd: LinearSegmentedColormap#
tol_colors.BuRd_r: LinearSegmentedColormap#
tol_colors.BuRd_discrete: ListedColormap#
tol_colors.BuRd_discrete_r: ListedColormap#

PRGn#

tol_colors.PRGn: LinearSegmentedColormap#
tol_colors.PRGn_r: LinearSegmentedColormap#
tol_colors.PRGn_discrete: ListedColormap#
tol_colors.PRGn_discrete_r: ListedColormap#

YlOrBr#

tol_colors.YlOrBr: LinearSegmentedColormap#
tol_colors.YlOrBr_r: LinearSegmentedColormap#
tol_colors.YlOrBr_discrete: ListedColormap#
tol_colors.YlOrBr_discrete_r: ListedColormap#

WhOrBr#

tol_colors.WhOrBr: LinearSegmentedColormap#
tol_colors.WhOrBr_r: LinearSegmentedColormap#
tol_colors.WhOrBr_discrete: ListedColormap#
tol_colors.WhOrBr_discrete_r: ListedColormap#

Iridescent#

tol_colors.iridescent: LinearSegmentedColormap#
tol_colors.iridescent_r: LinearSegmentedColormap#

Rainbow#

tol_colors.rainbow_discrete(n_colors: int = 22) ListedColormap#

Discrete rainbow colormaps.

The number of colors can vary between 1 and 23 (included).

Full rainbow

tol_colors.rainbow_WhBr: LinearSegmentedColormap#
tol_colors.rainbow_WhBr_r: LinearSegmentedColormap#
tol_colors.rainbow#

Alias for rainbow_WhBr.

tol_colors.rainbow_r#

Alias for rainbow_WhBr_r.

White to red

tol_colors.rainbow_WhRd: LinearSegmentedColormap#
tol_colors.rainbow_WhRd_r: LinearSegmentedColormap#

Purple to brown

tol_colors.rainbow_PuBr: LinearSegmentedColormap#
tol_colors.rainbow_PuBr_r: LinearSegmentedColormap#

Purple to red

tol_colors.rainbow_PuRd: LinearSegmentedColormap#
tol_colors.rainbow_PuRd_r: LinearSegmentedColormap#

Legacy API#

Present for backward compatibility, but should be replaced by alternatives above.

tol_colors.get_colorset(name: str = 'bright')#

Return discrete colorsets for qualitative data.

Deprecated since version 2.0: This function is soft-deprecated, please use colorsets instead.

Parameters:

name – Name of the color set. Hyphens are automatically replaced, so “hight-contrast” works as well.

tol_colors.tol_cset(colorset=None)#

Return discrete color sets for qualitative data.

Deprecated since version 2.0: This function is soft-deprecated, please use colorsets instead.

Parameters:

colorset (str) – Name of the color set. Hyphens are automatically replaced. If None return the list of possible sets. If not in defined sets, will default to ‘bright’.

tol_colors.get_colormap(name: str, n_colors: int = 22) LinearSegmentedColormap | ListedColormap#

Return continuous and discrete colormaps for ordered data.

Deprecated since version 2.0: This function is soft-deprecated, please use colorsets or rainbow_discrete() instead.

Parameters:
  • name – Name of the colormap. Hyphens are automatically replaced.

  • n_colors – Only used for “rainbow_discrete”: number of discrete colors to use.

tol_colors.tol_cmap(colormap: str | None = None, lut: int = 22) LinearSegmentedColormap | ListedColormap | list[str]#

Return continuous and discrete colormaps for ordered data.

Deprecated since version 2.0: This function is soft-deprecated, please use colorsets or rainbow_discrete() instead.

Parameters:
  • name – Name of the colormap. Hyphens are automatically replaced. If None return a list available colormaps. If not in defined maps, will default to ‘rainbow_PuRd’.

  • lut – Only used for “rainbow_discrete”: number of discrete colors to use.