MATLAB Functions | Help Desk |
contour
Two-dimensional contour plotcontour(Z)
contour(Z,n)
contour(Z,v)
contour(X,Y,Z)
contour(X,Y,Z,n)
contour(X,Y,Z,v)
contour(...,LineSpec
)
[C,h] = contour(...)
A contour plot displays isolines of matrix Z
. You label the contour lines using clabel
.
contour(Z)
draws a contour plot of matrix Z
, where Z
is interpreted as heights with respect to the x-y plane. Z
must be at least a 2-by-2 matrix. The number of contour levels and the values of the contour levels are chosen automatically based on the minimum and maximum values of Z
. The ranges of the x- and y-axis are [1:n]
and [1:m]
, where [m,n] = size(Z)
.
contour(Z,n)
draws a contour plot of matrix Z
with n
contour levels.
contour(Z,v)
draws a contour plot of matrix Z
with contour lines at the data values specified in vector v
. The number of contour levels is equal to length(v)
. To draw a single contour of level i
, use contour(Z,[i i])
.
contour(X,Y,Z), contour(X,Y,Z,n), and contour(X,Y,Z,v)
draw contour plots of Z
. X
and Y
specify the x- and y-axis limits. When X
and Y
are matrices, they must be the same size as Z
, in which case they specify a surface as surf
does.
contour(...,LineSpec)
draws the contours using the line type and color specified by LineSpec
. Marker symbols are ignored.
[C,h] = contour(...)
returns the contour matrix C
(see contourc
) and a vector of handles to graphics objects. clabel
uses the contour matrix C
to create the labels. contour
creates Patch graphics objects unless you specify LineSpec
, in which case contour
creates Line graphics objects.
If you do not specify LineSpec, colormap
and caxis
control the color.
If X
or Y
is irregularly spaced, contour
calculates contours using a regularly spaced contour grid, then transforms the data to X
or Y
.
To view a contour plot of the function
over the range -2 x 2, -2 y 3, create matrix Z
using the statements
xrange = -2:.2:2; yrange = -2:.2:3; [X,Y] = meshgrid(xrange,yrange); Z = X.*exp(-X.^2-Y.^2);Then, generate a contour plot of
Z
:
[C,h] = contour(X,Y,Z); clabel(C,h)View the same function using the default range and 20 evenly spaced contour lines:
contour(Z,20);Use
interp2
and contour
to create smoother contours:
Z = magic(4); [C,h] = contour(interp2(Z,4)); clabel(C,h)
clabel
, contour3
, contourc
, contourf
, quiver
The interp2
function in the MATLAB Language Reference Manual.