This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Using Colormaps

This example shows how to use colormaps in MATLAB®.

What is a Colormap?

A colormap is a three-column matrix of real numbers. Each row in the matrix is an RGB triplet value that defines one color in the colormap. MATLAB draws surfaces and other objects by mapping the data that defines the surface into the colors in the colormap.

The Default Colormap

The picture below shows a surface drawn with the default colormap, which is called parula.


Parula is the default colormap in MATLAB because it has a natural perceptual ordering (dark to light) and because it is perceptually uniform. Because of this property, smooth changes in the data are seen as smooth changes in color, while sharp changes in the data are seen as sharp changes in color.

Each built-in colormap has a corresponding function that returns the matrix of RGB triplets. The default size of a colormap is 64 colors.

my_colormap = parula;
ans = 1×2

    64     3

Change the Colormap

To change the colormap, use the colormap function. The colormap function takes a single input argument which is either the name of a built-in colormap or a three-column matrix of RGB triplet values. By default, the colormap function changes the colormap for everything in the current figure.


Create Multiple Colormaps Per Figure

To change the colormap for a specific figure or a specific axes within a figure, call the colormap function with a figure or axes object as the first argument. For example, use a different colormap for each axes in the figure.

ax1 = subplot(2,1,1);
colormap(ax1, autumn)

ax2 = subplot(2,1,2);
colormap(ax2, winter)

Set the Colormap Size

The size of the colormap determines how smooth the transition is between colors. A colormap with a small number of colors has sharp transitions between colors. A larger colormap provides much smoother transitions between colors. To change the number of colors in the colormap, pass an integer value to the built-in colormap.

shading interp

To use a larger colormap, pass a larger value to the built-in colormap.


Was this topic helpful?