MATLAB Function Reference
  Go to function:
    Search    Help Desk 
colormap    Examples   See Also

Set and get the current colormap

Syntax

Description

A colormap is an m-by-3 matrix of real numbers between 0.0 and 1.0. Each row is an RGB vector that defines one color. The kth row of the colormap defines the k-th color, where map(k,:) = [r(k) g(k) b(k)]) specifies the intensity of red, green, and blue.

colormap(map) sets the colormap to the matrix map. If any values in map are outside the interval [0 1], MATLAB returns the error: Colormap must have values in [0,1].

colormap('default') sets the current colormap to the default colormap.

cmap = colormap; retrieves the current colormap. The values returned are in the interval [0 1].

Specifying Colormaps

M-files in the color directory generate a number of colormaps. Each M-file accepts the colormap size as an argument. For example,

creates an hsv colormap with 128 colors. If you do not specify a size, MATLAB creates a colormap the same size as the current colormap.

Supported Colormaps

MATLAB supports a number of colormaps.

Examples

The Images and colormaps demo, imagedemo, provides an introduction to colormaps. Select Color Spiral from the menu (starts automatically on the Macintosh). This uses the pcolor function to display a 16-by-16 matrix whose elements vary from 0 to 255 in a rectilinear spiral. The hsv colormap starts with red in the center, then passes through yellow, green, cyan, blue, and magenta before returning to red at the outside end of the spiral. Selecting Colormap Menu gives access to a number of other colormaps (except on the Macintosh).

The rgbplot function plots colormap values. Try rgbplot(hsv), rgbplot(gray), and rgbplot(hot).

The following commands display the flujet data using the jet colormap:

The demos directory contains a CAT scan image of a human spine. To view the image:

Algorithm

Each Figure has its own Colormap property. colormap is an M-file that sets and gets this property.

See Also

brighten, caxis, contrast, hsv2rgb, pcolor, rgb2hsv, rgbplot

The Colormap property of Figure graphics objects.



[ Previous | Help Desk | Next ]