You can do this in MATLAB by using a “Colormap.”
A colormap is a matrix of three columns whose values are between 0 and 1 that define the colors for objects.
Each row in the matrix defines one color using an RGB triplet. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]. A value of 0 indicates no color and a value of 1 indicates full intensity.
You can use the “colormap” function to change the colormap of an axes or figure. You could create your own custom colormap or use MATLAB built-in colormaps.
Here’s an example of using a built-in colormap:
f = Figure %creates a figure
contourf(peaks) %contour plot
colormap(parula(12)) % set f to built-in colormap “parula”, the integer number specifies the number of colors to use from the parula colormap, 12 in this case.
Example to create custom colormap:
map = [0.2, 0.1, 0.5
0.1, 0.5, 0.8
0.2, 0.7, 0.6
0.8, 0.7, 0.3
0.9, 1, 0]; % this matrix defines a colormap containing five colors, the three columns stand for red,green and blue values respectively with intensities between 0 and 1.
surf(peaks);
colormap(map);
For more information on colormaps, check the documentation link below: