|On this page…|
Patch color data is interpreted in either of two ways:
Indexed Color Data — Numerical values that are mapped to colors defined in the figure colormap
Truecolor Data — RGB triples that define colors explicitly and do not make use of the figure colormap
The dimensions of the color data (CData or FaceVertexCData) determine how such data is interpreted. If you specify only one numeric value per patch, per face, or per vertex, the data is regarded as indexed. If there are three numeric values per patch, face, or vertex, the values are interpreted as RGB triplets.
Indexed color data can either be interpreted as values to scale before mapping to the colormap, or directly as indices into the colormap. You control the interpretation by setting the CDataMapping property. The default is to scale the data.
By default, the color data is scaled so that the minimum value maps to the first color in the colormap, the maximum value maps to the last color in the colormap, and values in between are linearly transformed to span the colormap. This enables you to use colormaps of different sizes without changing your data and to use data in any range of values without changing the colormap.
For example, the following patch has eight triangular faces with a total of 24 (nonunique) vertices. The color data are integers that range from one to 24, but could be any values.
The variable c contains the color data. It is a 3-by-8 matrix, with each column specifying the colors for the three vertices of each face.
c = 1 4 7 10 13 16 19 22 2 5 8 11 14 17 20 23 3 6 9 12 15 18 21 24
The color bar (colorbar) on the right side of the patch illustrates the colormap used and indicates with the vertical axis which color is mapped to the respective data value.
You can alter the mapping of color data to colormap entry using the caxis command. This command uses a two-element vector [cmin cmax] to specify what data values map to the beginning and end of the colormap, thereby shifting the color mapping.
By default, cmin is set to the minimum value and cmax to the maximum value of the color data of all graphics objects within the axes. However, you can set these limits to span any range of values and thereby shift the color mapping. See Calculating Color Limits in "Axes Properties" in the Using MATLAB® Graphics documentation for more information.
The color data does not need to be a sequential list of integers; it can be any matrix with dimensions matching the coordinate data. For example,
If you set the patch CDataMapping property to direct,
MATLAB graphic software interprets each color data value as a direct index into the colormap. That is, a value of 1 maps to the first color, a value of 2 maps to the second color, and so on.
The patch from the previous example would then use only the first 24 colors in the colormap.
This example uses integer color data. However, if the values are not integers, they are converted according to these rules:
If value is < 1, it maps to the first color in the colormap.
If value is not an integer, it is rounded to the nearest integer toward zero.
If value > length(colormap), it maps to the last color in the colormap.
Unscaled color data is more commonly used for images where there is typically a colormap associated with a particular image.
Truecolor is a means to specify a color explicitly with RGB values rather than pointing to an entry in the figure colormap. Truecolor generally provides a greater range of colors than can be defined in a colormap.
Using truecolor eliminates the mapping of data to colormap entries. On the other hand, you cannot change the coloring of the patch without redefining the color data (as opposed to just changing the colormap).
When you specify interpolated face coloring, the color of each face is determined by interpolating the vertex colors. The method of interpolation depends on whether you specified truecolor data or indexed color data.
With truecolor data, the numeric RGB values defined for the vertices are interpolated. This generally produces a smooth variation of color across the face. In contrast, indexed color interpolation uses only colors that are defined in the colormap. With certain colormaps, the results can be quite different.
To illustrate this difference, these two patches are defined with the same vertex colors. Circular markers indicate the yellow, red, and blue vertex colors.
The patch on the left uses indexed colors obtained from the six-element colormap shown next to it. The color data maps the vertex colors to the colormap elements indicated in the picture. With this colormap, interpolating from the cyan vertex to the blue vertex can include only the colors green, red, yellow, and magenta, hence the banding.
Interpolation in RGB space makes no use of the colormap. It is simply the gradual transition from one numeric value to another. For example, interpolating from the cyan vertex to the blue vertex follows a progression similar to these values.
0 1 1, 0 0.9 1, 0 0.8 1, ... 0 0.2 1, 0 0.1 1, 0 0 1
In reality each pixel would be a different color so the incremental change would be much smaller than illustrated here.