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.


3-D contour plot


[C,h] = contour3(...)


contour3 creates a 3-D contour plot of a surface defined on a rectangular grid.

contour3(Z) draws a contour plot of matrix Z in a 3-D view. Z is interpreted as heights with respect to the x-y plane. Z must be at least a 2-by-2 matrix that contains at least two different values. The x values correspond to the column indices of Z and the y values correspond to the row indices of Z. The contour levels are chosen automatically.

contour3(Z,n) draws a contour plot of matrix Z with n contour levels in a 3-D view.

contour3(Z,v) draws a contour plot of matrix Z with contour lines at the values specified in vector v. The number of contour levels is equal to length(v). Specifying the vector v sets the LevelListMode property to manual. To display a single contour line at a particular value, define v as a two-element vector with both elements equal to the desired contour level. For example, to draw a single contour of level k, use contour3(Z,[k k]).

contour3(X,Y,Z), contour3(X,Y,Z,n), and contour3(X,Y,Z,v) draw contour plots of Z using X and Y to determine the x and y values.

  • If X and Y are vectors, then length(X) must equal size(Z,2) and length(Y) must equal size(Z,1). The vectors must be strictly increasing or strictly decreasing and cannot contain any repeated values.

  • If X and Y are matrices, then their sizes must equal the size of Z. Typically, you should set X and Y so that the columns are strictly increasing or strictly decreasing and the rows are uniform (or the rows are strictly increasing or strictly decreasing and the columns are uniform).

If X or Y is irregularly spaced, then contour3 calculates contours using a regularly spaced contour grid, and then transforms the data to X or Y.

contour3(...,LineSpec) draws the contour lines using the line type and color specified by LineSpec. contour3 ignores marker symbols.

contour3(...,Name,Value) specifies contour properties using one or more property name, property value pairs. Name is the property name and must appear inside single quotes (''). Value is the corresponding value. For example, 'LineWidth',2 sets the contour line width to 2. For a list of contour property names and values, see Contour Properties.

contour3(ax,...) plots into the axes specified by ax instead of into the current axes (gca).

[C,h] = contour3(...) returns the contour matrix C containing the data that defines the contour lines and the Contour object h. The clabel function uses the contour matrix to label the contour lines.


collapse all

Set up matrices X and Y using the meshgrid function. Plot 30 contours of matrix Z.

x = -2:0.25:2;
[X,Y] = meshgrid(x);
Z = X.*exp(-X.^2-Y.^2);


If you do not specify LineSpec, the functions colormap and caxis control the color.

Label the contour lines using clabel.

contour3(...) works the same as contour(...) except that the contours are drawn at their corresponding z values.

See Also



Introduced before R2006a

Was this topic helpful?