matplotlib.colors#

Note

The Colortutorials andexamples demonstrate how to set colors and colormaps. You may wantto read those instead.

A module for converting numbers or color arguments toRGB orRGBA.

RGB andRGBA are sequences of, respectively, 3 or 4 floats in therange 0-1.

This module includes functions and classes for color specification conversions,and for mapping numbers to colors in a 1-D array of colors called a colormap.

Mapping data onto colors using a colormap typically involves two steps: a dataarray is first mapped onto the range 0-1 using a subclass ofNormalize,then this number is mapped to a color using a subclass ofColormap. Twosubclasses ofColormap provided here:LinearSegmentedColormap, which usespiecewise-linear interpolation to define colormaps, andListedColormap, whichmakes a colormap from a list of colors.

See also

Creating Colormaps in Matplotlib for examples of how tomake colormaps and

Choosing Colormaps in Matplotlib for a list of built-in colormaps.

Colormap normalization for more details about datanormalization

More colormaps are available atpalettable.

The module also provides functions for checking whether an object can beinterpreted as a color (is_color_like), for converting such an objectto an RGBA tuple (to_rgba) or to an HTML-like hex string in the"#rrggbb" format (to_hex), and a sequence of colors to an (n, 4)RGBA array (to_rgba_array). Caching is used for efficiency.

Colors that Matplotlib recognizes are listed atSpecifying colors.

Color norms#

Normalize([vmin, vmax, clip])

A class which, when called, maps values within the interval[vmin,vmax] linearly to the interval[0.0,1.0].

NoNorm([vmin, vmax, clip])

Dummy replacement forNormalize, for the case where we want to use indices directly in aScalarMappable.

AsinhNorm([linear_width, vmin, vmax, clip])

The inverse hyperbolic sine scale is approximately linear near the origin, but becomes logarithmic for larger positive or negative values.

BoundaryNorm(boundaries, ncolors[, clip, extend])

Generate a colormap index based on discrete intervals.

CenteredNorm([vcenter, halfrange, clip])

Normalize symmetrical data around a center (0 by default).

FuncNorm(functions[, vmin, vmax, clip])

Arbitrary normalization using functions for the forward and inverse.

LogNorm([vmin, vmax, clip])

Normalize a given value to the 0-1 range on a log scale.

PowerNorm(gamma[, vmin, vmax, clip])

Linearly map a given value to the 0-1 range and then apply a power-law normalization over that range.

SymLogNorm(linthresh[, linscale, vmin, ...])

The symmetrical logarithmic scale is logarithmic in both the positive and negative directions from the origin.

TwoSlopeNorm(vcenter[, vmin, vmax])

Normalize data with a set center.

Univariate Colormaps#

Colormap(name[, N, bad, under, over])

Baseclass for all scalar to RGBA mappings.

LinearSegmentedColormap(name, segmentdata[, ...])

Colormap objects based on lookup tables using linear segments.

ListedColormap(colors[, name, N, bad, ...])

Colormap object generated from a list of colors.

Multivariate Colormaps#

BivarColormap([N, M, shape, origin, name])

Base class for all bivariate to RGBA mappings.

SegmentedBivarColormap(patch[, N, shape, ...])

BivarColormap object generated by supersampling a regular grid.

BivarColormapFromImage(lut[, shape, origin, ...])

BivarColormap object generated by supersampling a regular grid.

Other classes#

ColorSequenceRegistry()

Container for sequences of colors that are known to Matplotlib by name.

LightSource([azdeg, altdeg, hsv_min_val, ...])

Create a light source coming from the specified azimuth and elevation.

Functions#

from_levels_and_colors(levels, colors[, extend])

A helper routine to generate a cmap and a norm instance which behave similar to contourf's levels and colors arguments.

hsv_to_rgb(hsv)

Convert HSV values to RGB.

rgb_to_hsv(arr)

Convert an array of float RGB values (in the range [0, 1]) to HSV values.

to_hex(c[, keep_alpha])

Convertc to a hex color.

to_rgb(c)

Convert thecolorc to an RGB color tuple.

to_rgba(c[, alpha])

Convertc to an RGBA color.

to_rgba_array(c[, alpha])

Convertc to a (n, 4) array of RGBA colors.

is_color_like(c)

Return whetherc as a valid Matplotlibcolor specifier.

same_color(c1, c2)

Return whether the colorsc1 andc2 are the same.

get_named_colors_mapping()

Return the global mapping of names to named colors.

make_norm_from_scale(scale_cls[, ...])

Decorator for building aNormalize subclass from aScaleBase subclass.

Exported colors#

The data used to populate theList of named colors are exposedas dictionaries that map color names to hex strings.

matplotlib.colors.BASE_COLORS#
matplotlib.colors.TABLEAU_COLORS#
matplotlib.colors.CSS4_COLORS#
matplotlib.colors.XKCD_COLORS#