Navigation

Operators and Keywords

Function List:

C++ API

: contourf (z)
: contourf (z, vn)
: contourf (x, y, z)
: contourf (x, y, z, vn)
: contourf (…, style)
: contourf (hax, …)
: [c, h] = contourf (…)

Create a 2-D contour plot with filled intervals.

Plot level curves (contour lines) of the matrix z and fill the region between lines with colors from the current colormap.

The level curves are taken from the contour matrix c computed by contourc for the same arguments; see the latter for their interpretation.

The appearance of contour lines can be defined with a line style style in the same manner as plot. Only line style and color are used; Any markers defined by style are ignored.

If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca.

The optional output c contains the contour levels in contourc format.

The optional return value h is a graphics handle to the hggroup comprising the contour lines.

The following example plots filled contours of the peaks function.

[x, y, z] = peaks (50);
contourf (x, y, z, -7:9)

See also: ezcontourf, contour, contourc, contour3, clabel, meshc, surfc, caxis, colormap, plot.

Demonstration 1

The following code

 clf;
 colormap ("default");
 [x, y, z] = peaks (50);
 contourf (x, y, z, -7:9);
 title ({"contourf() plot (filled contour lines)"; "Z = peaks()"});

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 colormap ("default");
 [theta, r] = meshgrid (linspace (0,2*pi,64), linspace (0,1,64));
 [X, Y] = pol2cart (theta, r);
 Z = sin (2*theta) .* (1-r);
 contourf (X, Y, abs (Z), 10);
 title ({"contourf() plot"; "polar fcn: Z = sin (2*theta) * (1-r)"});

Produces the following figure

Figure 1

Demonstration 3

The following code

 clf;
 colormap ("default");
 x = linspace (-2, 2);
 [x, y] = meshgrid (x);
 z = sqrt (x.^2 + y.^2) ./ (x.^2 + y.^2 + 1);
 contourf (x, y, z, [0.4, 0.4]);
 title ("Hole should be filled with the background color");

Produces the following figure

Figure 1

Package: octave