This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Plot a contour graph under mesh graph


h = meshc(...)


meshc(X,Y,Z) draws a wireframe mesh and a contour plot under it with color determined by Z, so color is proportional to surface height. If X and Y are vectors, length(X) = n and length(Y) = m, where [m,n] = size(Z). In this case, (X(j), Y(i), Z(i,j)) are the intersections of the wireframe grid lines; X and Y correspond to the columns and rows of Z, respectively. If X and Y are matrices, (X(i,j), Y(i,j), Z(i,j)) are the intersections of the wireframe grid lines.

meshc(Z) draws a contour plot under wireframe mesh using X = 1:n and Y = 1:m, where [m,n] = size(Z). The height, Z, is a single-valued function defined over a rectangular grid. Color is proportional to surface height.

meshc(...,C) draws a meshc graph with color determined by matrix C. MATLAB® performs a linear transformation on the data in C to obtain colors from the current colormap. If X, Y, and Z are matrices, they must be the same size as C.

meshc(axes_handles,...) plots into the axes with handle axes_handle instead of the current axes (gca).

h = meshc(...) returns handles to the Surface Properties and Contour Properties graphics object.


collapse all

Use meshc to display a combination of a mesh plot and a contour plot of the peaks function.

[X,Y] = meshgrid(-3:.125:3);
Z = peaks(X,Y);


meshc does not accept complex inputs.

A mesh is drawn as a Surfaceplot graphics object with the viewpoint specified by view(3). The face color is the same as the background color (to simulate a wireframe with hidden-surface elimination), or none when drawing a standard see-through wireframe. The current colormap determines the edge color. The hidden command controls the simulation of hidden-surface elimination in the mesh, and the shading command controls the shading model.


The range of X, Y, and Z, or the current settings of the axes XLimMode, YLimMode, and ZLimMode properties, determine the axis limits. axis sets these properties.

The range of C, or the current settings of the axes CLim and CLimMode properties (also set by the caxis function), determine the color scaling. Use the scaled color values are used as indices into the current colormap.

The mesh rendering functions produce color values by mapping the z data values (or an explicit color array) onto the current colormap. The MATLAB default behavior is to compute the color limits automatically using the minimum and maximum data values (also set using caxis auto). The minimum data value maps to the first color value in the colormap and the maximum data value maps to the last color value in the colormap. MATLAB performs a linear transformation on the intermediate values to map them to the current colormap.

meshc calls mesh, turns hold on, and then calls contour and positions the contour on the x-y plane. For additional control over the appearance of the contours, issue these commands directly. You can combine other types of graphs in this manner, for example surf and pcolor plots.

meshc assumes that X and Y are monotonically increasing. If X or Y is irregularly spaced, contour3 calculates contours using a regularly spaced contour grid, and then it transforms the data to X or Y.

Extended Capabilities

Introduced before R2006a