Documentation Center

  • Trial Software
  • Product Updates


Filled 2-D contour plot


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



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,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]).


  • 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.





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.


expand all

Create Filled Contour Plot


Z = peaks(20);

More About

expand all


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?