# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# 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(...,Name,Value) contourf(ax,...) [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 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.

`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`. 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 `contourf(Z,[k k])`. Specifying the vector `v` sets the `LevelListMode` property to manual.

`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 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 `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(...,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.

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

`[C,h] = contourf(...)` returns the contour matrix `C` containing the data that defines the contour lines and a `Contour` object `h`. The `ContourMatrix` property for the `Contour` object also contains the contour matrix. The `clabel` function uses the contour matrix to label the contour lines.

## Examples

collapse all

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)```

## Tips

`NaN` values in `Z` leave white holes with black borders in the contour plot.