Gray colormap array
c = gray returns the gray colormap as a three-column array with the same
number of rows as the colormap for the current figure (
gcf). If no figure exists, then the
number of rows is equal to the default length of 256. Each row in the array contains
the red, green, and blue intensities for a specific color. The intensities are in
the range [0,1], and the color scheme looks like this image.
Reverse the Colormap
Plot a surface and assign the gray colormap.
Get the gray colormap array and reverse the order. Then apply the modified colormap to the surface.
c = gray; c = flipud(c); colormap(c);
Downsample the Gray Colormap
Get a downsampled version of the gray colormap containing only twenty colors. Then display the contours of a paraboloid by applying the colormap and interpolated shading.
c = gray(20); [X,Y] = meshgrid(-10:1:10); Z = X.^2 + Y.^2; surf(X,Y,Z); colormap(c); shading interp;
Version HistoryIntroduced before R2006a
R2019b: Colormaps have 256 colors by default
Starting in R2019b, colormaps have 256 colors by default.
In R2019a and previous releases, the default size is 64. If you have code that
depends on a colormap having 64 colors, specify the number of colors when you set
the colormap for the figure, axes, or chart. For example,
colormap(gray(64)) sets the figure's colormap to the 64-color
Alternatively, you can change the default colormap for all figures within your MATLAB® session: