### Navigation

- index
- modules |
- next |
- previous |
- home|
- examples|
- tutorials|
- pyplot|
- docs »
- The Matplotlib API »

# 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.

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

To use the colors that are part of the active color cycle in the current style, use `C` followed by a digit. For example:

> - `C0`: The first color in the cycle
> - `C1`: The second color in the cycle

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'

(possibly specifying an alpha value as well), or you can pass an `(r, g, b)` or `(r, g, b, a)` tuple, where each of `r`, `g`, `b` and `a` are in the range [0,1].

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

### Classes

`BoundaryNorm`(boundaries, ncolors[, clip]) | Generate a colormap index based on discrete intervals.
`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.

### 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 in a numpy array to rgb values
`rgb_to_hsv`(arr) | convert float rgb values (in the range [0, 1]), in a numpy array to hsv
`to_hex`(c[, keep_alpha]) | Convert `c` to a hex color.
`to_rgb`(c) | Convert `c` to an RGB color, silently dropping the alpha channel.
`to_rgba`(c[, alpha]) | Convert `c` to an RGBA color.
`to_rgba_array`(c[, alpha]) | Convert `c` to a (n, 4) array of RGBA colors.
`is_color_like`(c) | Return whether `c` can be interpreted as an RGB(A) color.
`makeMappingArray`(N, data[, gamma]) | Create an N -element 1-d lookup table
`get_named_colors_mapping`() | Return the global mapping of names to named colors.