Documentation Center

  • Trial Software
  • Product Updates

Specifying Patch Coloring

Patch Color Properties

Patch coloring is defined differently from surface object coloring in that patches do not automatically generate color data based on the value of the z-coordinate at each vertex. You must explicitly specify patch coloring if you do not want the default white face color and black edge color.

You can specify patch face coloring by defining

  • A single color for all faces

  • One color for each face, which is used for flat coloring

  • One color for each vertex, which is used for interpolated coloring

Specify the face color using either the CData property, if you are using x-, y-, and z-coordinates, or the FaceVertexCData property, if you are specifying vertices and faces.

This table summarizes the patch properties that control color (exclusive of those used when light sources are present).

PropertyPurpose
CData

Specify single, per face, or per vertex colors in conjunction with x, y, and z data

CDataMapping

Specifies whether color data is scaled or used directly as indices into the figure colormap

FaceVertexCData

Specify single, per face, or per vertex colors in conjunction with faces and vertices data

EdgeColor

Specifies whether edges are invisible, a single color, a flat color determined by vertex colors, or interpolated colors determined by vertex colors

FaceColor

Specifies whether faces are invisible, a single color, a flat color determined by vertex colors, or interpolated colors determined by vertex colors

MarkerEdgeColor

Specifies the color of the marker, or the edge color for filled markers

MarkerFaceColor

Specifies the fill color for markers that are closed shapes

Patch Edge Coloring

Each patch face has a bounding edge, which you can color as

  • A single color for all edges

  • A flat color defined by the color of the vertex that precedes the edge

  • Interpolated colors determined by the two vertices that bound the edge

Patch edge colors can be flat or interpolated only when you specify a color for each vertex. Flat edge coloring uses the color of the vertex preceding the edge to determine the color of the edge. The order in which you specify the vertices establishes which vertex colors a particular edge.

The following examples illustrate patch edge coloring:

Example — Specifying Flat Edge and Face Coloring

These statements create a square patch.

v  = [0 0 0;1 0 0;1 1 0;0 1 0];
f = [1 2 3 4];
fvc = [1 0 0;0 1 0;1 0 1;1 1 0];
patch('Vertices',v,'Faces',f,'FaceVertexCData',fvc,...
      'FaceColor','flat','EdgeColor','flat',...
      'Marker','o','MarkerFaceColor','flat')

The Faces property value, [1 2 3 4], determines the order in which MATLAB® connects the vertices. In this case, the order is red, green, magenta, and yellow. If you change this order, the results can be quite different. For example, specifying the Faces property as

f = [4 3 2 1];

changes the order to yellow, magenta, green, and red. Changing the order not only changes the color of the edges, but also the color of the face, which is the color of the first vertex specified.

Coloring Edges with Shared Vertices

Each patch face is bound by edges, which are line segments that connect the vertices. When patches have multiple faces that share vertices, some of the edges might overlap. In such cases, the edges of the most recently drawn face overlie previously drawn edges.

For example, this illustration shows a patch with four faces and flat colored edges (FaceColor set to none, EdgeColor set to flat).

The arrows indicate the order in which each edge is drawn in the first, second, third, and fourth face. The color at each vertex determines the color of the edge that follows it. Notice how the second edge in the first face would be green except that the second face drew its fourth edge from the magenta vertex. You can see similar effects in all shared edges.

For EdgeColor set to interp, MATLAB interpolates colors between adjacent vertices. In this case, the order in which you specify the vertices does not affect the edge color.

Was this topic helpful?