For many types of visualizations you create, MATLAB® maps the full range of your data to the colormap by default. The smallest value in your data maps to the first row in the colormap, and the largest value maps to the last row in the colormap. All intermediate values map linearly to the intermediate rows of the colormap.
This default mapping is useful in most cases, but you can perform the mapping over any range you choose, even if the range you choose is different than the range of your data. Choosing a different mapping range allows you to:
See where your data is at or beyond the limits of that range.
See where your data lies within that range.
Consider the surface Z = X + Y, where –10 ≤ x ≤ 10 and –10 ≤ y ≤ 10.
[X,Y] = meshgrid(-10:10); Z = X + Y; s = surf(X,Y,Z); xlabel('X'); ylabel('Y'); zlabel('Z = C'); colorbar
How Surface Plot Data Relates to a Colormap describes the
properties that control the color in this presentation. Essentially,
CData property of the
contains an array
C that associates each grid point
on the surface to a color in the colormap. By default,
Z is the array
containing the values of z = f(x,y)
at the grid points. Thus, the colors vary with changes in
The mapping range is controlled by the
Axes object. This property contains a two-element
vector of the form
[cmin cmax]. The default value
cmin is equal to the smallest value of
and the default value of
cmax is the largest value
C. In this case,
20] because the range of
C reflects the
[0 20] clips
all the values at or below
0 to the first color
in the colormap.
This command changes the
[0 20]. Notice that the lower half of the surface
maps to the first color in the colormap (dark blue). This clipping
C (which is equal to
is less than or equal to zero at those points.
You can also widen the mapping range to see where your data
lies within that range. For example, changing the range to
20] results in a surface that only uses half of the colors.
The lower half of the colormap corresponds to values that are outside
the range of
C, so those colors are not represented
on the surface.
You can set the
CLim property for surface
plots, patches, images, or any graphics object that uses a colormap.
However, this property only affects graphics objects that have the
'scaled'. If the
is set to
'direct', then all values of
directly into the colormap without any scaling. Any values of
are less than 1 are clipped to the first color in the colormap. Any
C that are greater than the length of
the colormap are clipped to the last color in the colormap.