Back to Data Visualization

colormap

Set or get colormap for current figure

Syntax

colormap(name)
colormap(map)
cmap = colormap

Description

Sets the colormap used for pseudocolor plots like imagesc, mesh, and surf. With no arguments, returns the current colormap as an Mx3 RGB matrix (default 256 rows). With a string argument, sets to a named colormap. With an Mx3 matrix argument, sets a custom colormap where each row is [R G B] with values in range [0,1].

Parameters

NameDescription
name(optional)Colormap name: viridis (default), jet, hot, cool, gray, grayscale, parula, turbo, coolwarm, rainbow, bone, copper, spring, summer, autumn, winter
map(optional)Mx3 matrix of RGB values (each in [0,1])

Returns

Mx3 RGB matrix (query mode) or null (set mode)

Examples

Try It
>> imagesc(peaks(30));
colormap('jet');
colorbar
Try It
>> surf(peaks(25));
colormap('hot')
Try It
>> cmap = colormap  % returns 256x3 matrix
Try It
>> colormap([0 0 1; 1 1 1; 1 0 0])  % custom blue-white-red

See Also