mpl.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 a single instance, colorConverter, of the ColorConverter class providing methods for converting single color specifications or sequences of them to RGB or RGBA.

Commands which take color arguments can use several formats to specify the colors. For the basic built-in colors, you can use a single letter

  • b: blue
  • g: green
  • r: red
  • c: cyan
  • m: magenta
  • y: yellow
  • k: black
  • w: white

Gray shades can be given as a string encoding a float in the 0-1 range, e.g.:

color = '0.75'

For a greater range of colors, you have two options. You can specify the color using an html hex string, as in:

color = '#eeefff'

or you can pass an R , G , B tuple, where each of R , G , B are in the range [0,1].

Finally, legal html names for colors, like ‘red’, ‘burlywood’ and ‘chartreuse’ are supported.

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.
hex2color(s) Take a hex string s and return the corresponding rgb 3-tuple
hsv_to_rgb(hsv) convert hsv values in a numpy array to rgb values
is_color_like(c) Return True if c can be converted to RGB
makeMappingArray(N, data[, gamma]) Create an N -element 1-d lookup table
rgb2hex(rgb) Given an rgb or rgba sequence of 0-1 floats, return the hex string
rgb_to_hsv(arr) convert float rgb values (in the range [0, 1]), in a numpy array to hsv

Classes

BoundaryNorm(boundaries, ncolors[, clip]) Generate a colormap index based on discrete intervals.
ColorConverter Provides methods for converting color specifications to RGB or RGBA
Colormap(name[, N]) Baseclass for all scalar to RGBA mappings.
LightSource([azdeg, altdeg, hsv_min_val, ...]) Create a light source coming from the specified azimuth and elevation.
LinearSegmentedColormap(name, segmentdata[, ...]) Colormap objects based on lookup tables using linear segments.
ListedColormap(colors[, name, N]) Colormap object generated from a list of colors.
LogNorm([vmin, vmax, clip]) Normalize a given value to the 0-1 range on a log scale
NoNorm([vmin, vmax, clip]) Dummy replacement for Normalize, for the case where we want to use indices directly in a ScalarMappable .
Normalize([vmin, vmax, clip]) A class which, when called, can normalize data into the [0.0, 1.0] interval.
PowerNorm(gamma[, vmin, vmax, clip]) Normalize a given value to the [0, 1] interval with a power-law scaling.
SymLogNorm(linthresh[, linscale, vmin, ...]) The symmetrical logarithmic scale is logarithmic in both the positive and negative directions from the origin.
zip alias of izip