MATLAB: How to fully utilize the full range of the colors in the color map for better visualization in the contour plot

MATLAB

When I set the color map to span a specific range of my data in my contour plot, the plot ends up displaying only a few levels and colors. I would like to utilize more of the 64 colors in the color map to better visualize my data.

Best Answer

The number of levels in a contour plot, and hence the number of colors used, can be specified when using the CONTOUR function. The following example illustrates the effect of specifying a larger number of levels in CONTOUR. To see the example, execute the following code at the MATLAB command line:
a = peaks;
f = figure;
ah1 = subplot(1,2,1); contour(a,20)
ah2 = subplot(1,2,2); contour(a,5)
cmin = -5;
cmax = 5;
set(ah1, 'CLim', [cmin cmax], 'CLimMode', 'manual')
set(ah2, 'CLim', [cmin cmax], 'CLimMode', 'manual')