contour

Creates a 2D contoured surface in an axes.

Syntax

contour(z)

contour(x, y, z)

contour(hAxes, ...)

contour(..., cn)

Inputs

x
Range of the x axis.
Type: double | integer
Dimension: vector | matrix
If X is a vector, its length must be equal to the number of columns of Z.
If X is a matrix, it must have the same size as Z.
y
Range of the y axis.
Type: double | integer
Dimension: vector | matrix
If Y is a vector, its length must be equal to the number of rows of Z.
If Y is a matrix, it must have the same size as Z.
z
Range of the z axis.
Type: double | integer
Dimension: matrix
hAxes
Axis handle.
Type: double
Dimension: scalar
cn
Optional argument to set the number of contours, changing the number of colors in the colormap. The number of colors is limited to 500.
Type: integer
Dimension: scalar

Examples

contour example:
cla;
x=[0:0.15:2*pi];
y=x;
z=sin(x')*cos(y);
contour(z);
Figure 1. Contour plot


Number of contours example:
cla;
x=[0:0.15:2*pi];
y=x;
z=sin(x')*cos(y);
contour(z, 4);
Figure 2. Contour plot with four color levels


x and y inputs of contour as vectors:
x = linspace(-2*pi,2*pi,50);
y = linspace(0,2*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X).*cos(Y);

contour(x,y,Z);

Comments

If there are no axes, one will be created first. If x and y are omitted, the index of the columns of z is used for x coordinates and the index of the rows of z is used for y coordinates. If the first argument of contour() is an axes handle, surfaces will be created in that axes.

The 'contourtype' of an axes object that contains a contoured surface is set to 'discrete'.