ContourPlot
Plots level sets (contours) of planar scalar fields.
Syntax
-
ContourPlot(f, ❨xmin, xmax[, δx]❩, ❨ymin, ymax[, δy]❩[, levels[, opts]])
-
f
is a function D → ℝ where D ⊂ ℝ² -
xmin
,xmax
,ymin
, andymax
are real numbers -
δx
andδy
are positive real numbers -
levels
is a positive integer or a real vector -
opts
is a string containing zero or more ofi
ands
-
‣ Note: Vector brackets can be inserted by pressing Shift+Ctrl+V.
Description
If f
is a scalar field D → ℝ, where D ⊂ ℝ², then
ContourPlot(f, ❨xmin, xmax, δx❩, ❨ymin, ymax, δy❩)
will produce a contour plot of f
in the region [xmin, xmax]×[ymin, ymax] ⊂ D.
Mathematically, this plot consists of the level curves
Γ_c = { (x, y) ∈ D : f(x, y) = c }
for various values of the constant c ∈ ℝ. By default, 12 level curves are plotted with equidistant levels within the estimated range of f on D determined by sampling the function on a regular grid within [xmin, xmax]×[ymin, ymax].
Specifically, if the sampled values range from A
to B > A
, then
c_i = A + i⋅(B − A) / 13, for i = 1, 2, ..., 12.
Notice that c_i
is never equal to A
or B
.
If the levels
argument is specified as an integer, then this number of levels will be used instead of 12. And if levels
is a real vector, then the components of levels
will be used as the levels; in this case, the number of levels will be the dimension of levels
.
δx
and δy
specify the resolution of the grid used when sampling f
(both to determine the range and when constructing the level curves). If omitted, default values will be used, so that the number of samples will be about 250 000. This default value can be changed; it’s an Algosim setting (Numerics_ContourSamplesPerAxis
).
The ContourPlot
function determines the contours by means of a “marching squares” algorithm with interpolation. Each contour produced is then investigated to see if it can be simplified. Chiefly, segments of straight lines are conics are detected. In the first case, the vertices in a straight-line segment are replaced by only the endpoints.
If omitted, the opts
(options) parameter is set to "is"
, which means that the interpolation (i
) and simplification (s
) steps are to be performed. Each of these steps can be suppressed by explicitly specifying a different value of opts
(such as "i"
, "s"
, or the empty string ""
).
Examples
ContourPlot((x, y) ↦ sin(x)^4 + sin(y)^4, ❨−π, π❩, ❨−π, π❩)
ContourPlot((x, y) ↦ sin(x)^2 − sin(y)^2, ❨−π, π❩ / 2, ❨−π, π❩ / 4, 50)