Documentation Center

  • Trials
  • Product Updates


Set and get current colormap


cmap = colormap


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,


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:

  • autumn varies smoothly from red, through orange, to yellow.

  • bone is a grayscale colormap with a higher value for the blue component. This colormap is useful for adding an "electronic" look to grayscale images.

  • colorcube contains as many regularly spaced colors in RGB color space as possible, while attempting to provide more steps of gray, pure red, pure green, and pure blue.

  • cool consists of colors that are shades of cyan and magenta. It varies smoothly from cyan to magenta.

  • copper varies smoothly from black to bright copper.

  • flag consists of the colors red, white, blue, and black. This colormap completely changes color with each index increment.

  • gray returns a linear grayscale colormap.

  • hot varies smoothly from black through shades of red, orange, and yellow, to white.

  • hsv varies the hue component of the hue-saturation-value color model. The colors begin with red, pass through yellow, green, cyan, blue, magenta, and return to red. The colormap is particularly appropriate for displaying periodic functions. hsv(m) is the same as hsv2rgb([h ones(m,2)]) where h is the linear ramp, h = (0:m–1)'/m.

  • jet ranges from blue to red, and passes through the colors cyan, yellow, and orange. It is a variation of the hsv colormap. The jet colormap is associated with an astrophysical fluid jet simulation from the National Center for Supercomputer Applications. See Examples.

  • lines produces a colormap of colors specified by the axes ColorOrder property and a shade of gray.

  • pink contains pastel shades of pink. The pink colormap provides sepia tone colorization of grayscale photographs.

  • prism repeats the six colors red, orange, yellow, green, blue, and violet.

  • spring consists of colors that are shades of magenta and yellow.

  • summer consists of colors that are shades of green and yellow.

  • white is an all white monochrome colormap.

  • winter consists of colors that are shades of blue and green.


expand all

Use Summer Colormap

Create a surface plot of the peaks function.


Change the colormap to the summer colormap.


Use Bone Colormap

Load the spine data set to get array X. Use the image function to display the data in X.

load spine

Change the colormap to the bone colormap.



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.

More About

expand all


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

See Also

| | | | | | | |

Was this topic helpful?