colors¶
For a visual representation of the matplotlib colormaps, see the “Color” section in the gallery.
matplotlib.colors¶
A module for converting numbers or color arguments to RGB or RGBA
RGB and RGBA are sequences of, respectively, 3 or 4 floats in the range 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. Colormapping typically involves two steps: a data array is first
mapped onto the range 0-1 using an instance of Normalize or of a
subclass; then this number in the 0-1 range is mapped to a color using an
instance of a subclass of Colormap. Two are provided here:
LinearSegmentedColormap, which is used to generate all the built-in
colormap instances, but is also useful for making custom colormaps, and
ListedColormap, which is used for generating a custom colormap from a
list of color specifications.
The module also provides functions for checking whether an object can be
interpreted as a color (is_color_like()), for converting such an object
to 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.
Matplotlib recognizes the following formats to specify a color:
- an RGB or RGBA tuple of float values in
[0, 1](e.g.,(0.1, 0.2, 0.5)or(0.1, 0.2, 0.5, 0.3)); - a hex RGB or RGBA string (e.g.,
'#0F0F0F'or'#0F0F0F0F'); - a string representation of a float value in
[0, 1]inclusive for gray level (e.g.,'0.5'); - one of
{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}; - a X11/CSS4 color name;
- a name from the xkcd color survey;
prefixed with
'xkcd:'(e.g.,'xkcd:sky blue'); - one of
{'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}which are the Tableau Colors from the ‘T10’ categorical palette (which is the default color cycle); - a “CN” color spec, i.e.
'C'followed by a single digit, which is an index into the default property cycle (matplotlib.rcParams['axes.prop_cycle']); the indexing occurs at artist creation time and defaults to black if the cycle does not include color.
All string specifications of color, other than “CN”, are case-insensitive.
