Skip to Main Content Skip to Search
Product Documentation

colormap - Set and get current colormap

Alternatives

Select a built-in colormap with the Property Editor. To modify the current colormap, use the Colormap Editor, accessible from Edit > Colormap on the figure menu.

Syntax

colormap(map)
colormap('default')
cmap = colormap
colormap(ax,...)

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 kth 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], you receive 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].

colormap(ax,...) uses the figure corresponding to axes ax instead of the current figure.

Specifying Colormaps

Files in the color folder generate a number of colormaps. Each file accepts the colormap size as an argument. For example,

colormap(hsv(128))

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

Supported Colormaps

The built-in MATLAB colormaps are illustrated and described below. In addition to specifying built-in colormaps programmatically, you can use the Colormap menu in the Figure Properties pane of the Plot Tools GUI to select one interactively.

The named built-in colormaps are the following:

Examples

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:

load flujet
image(X)
colormap(jet)

 

The demos folder contains a CAT scan image of a human spine. Use the image function to view the data:

load spine 
image(X)
colormap bone

Algorithms

Each figure has its own colormap property. colormap is a function that sets and gets this property.

See Also

brighten | caxis | colorbar | colormapeditor | contrast | hsv2rgb | pcolor | rgb2hsv | rgbplot

How To

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS