Quantcast

Documentation Center

  • Trial Software
  • Product Updates

contourf

Filled 2-D contour plot

Syntax

contourf(Z)
contourf(Z,n)
contourf(Z,v)
contourf(X,Y,Z)
contourf(X,Y,Z,n)
contourf(X,Y,Z,v)
contourf(...,LineSpec)
contourf(axes_handle,...)
contour(axes_handle,...)
[C,h] = contourf(...)

Description

A filled contour plot displays isolines calculated from matrix Z and fills the areas between the isolines using constant colors corresponding to the current figure's colormap.

contourf(Z) draws a filled 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 that contains at least two different values. The number of contour lines and the values of the contour lines 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).

contourf(Z,n) draws a filled contour plot of matrix Z with n contour levels.

contourf(Z,v) draws a filled contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v. Specifying the vector v sets the LevelListMode to manual to allow user control over contour levels. 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 i, use contourf(Z,[i i]).

contourf(X,Y,Z), contourf(X,Y,Z,n), and contourf(X,Y,Z,v) draw filled contour plots of Z using X and Y to determine the x- and y-axis limits.

  • If X and Y are vectors, then the length of X must equal the number of columns in Z and the length of Y must equal the number of rows in Z.

  • If X and Y are matrices, then their sizes must equal the size of Z.

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

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

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

contour(axes_handle,...) plots into axes axes_handle instead of gca.

[C,h] = contourf(...) returns a contour matrix, C, that contains the data that defines the contour lines, and a handle, h, to a contourgroup object containing the filled contours. The clabel function uses contour matrix C to label the contour lines. ContourMatrix is also a read-only Contourgroup property that you can obtain from the returned handle.

Examples

expand all

Create Filled Contour Plot

Use the peaks function to define z as a 20-by-20 matrix. Create a filled contour plot of z with 10 contour lines.

Z = peaks(20);
contourf(Z,10);

More About

expand all

Tips

Label the contour lines using clabel.

NaNs in the Z-data leave white holes with black borders in the contour plot.

See Also

| | | | |

Was this topic helpful?