contour

A two-variable expression drawn as its level sets. The expression is in x AND y ((x - 2)^2 + (y - 3)^2), grid-sampled over the visible window and traced where it takes equal values, so panning re-samples the surface and a parameter in the expression moves the level sets live. y is the vertical axis here, not a parameter: only the letters beyond x and y get footer sliders.

contourNode
Only withxyargandpolarplane
Eight concentric contour rings around the point (2, 3).Eight concentric contour rings around the point (2, 3).

A contour draws the level sets of a function of the plane, either levels: 8 evenly spaced or at: 1, 2, 4 exactly. Its expression may use y alongside x, which only a contour and a surface allow. It takes a colour that is a single hue or a ramp — multicolour (the full spectrum) or temperature (blue through white to red) — and exposes derived min and max over the visible window. A surface of the same expression paints the field its lines are drawn through.

The field sin x · cos y painted on the blue-to-red temperature ramp, with its zero contour in grey.The field sin x · cos y painted on the blue-to-red temperature ramp, with its zero contour in grey.
canvas.graph{
    surface(expression: sin(x) * cos(y); colour: temperature)
    contour(expression: sin(x) * cos(y); at: 0; colour: grey)
}

#Attributes

expressionRequiredImplicitAnimatable
Math expression for the surface's value at (x, y). Free letters beyond x and y are parameters.
Also written: exp, f, func, functionCan be written as shorthand: contour:value
levelsAnimatable
How many level sets to draw — resolved to round values of the expression, the way axis ticks are chosen.
Default12
atAnimatable
The exact level values, overriding levels:, for surfaces whose structure even spacing misrepresents — a quadratic bowl wants 1, 4, 9, 16. Entries are parametised: at: k, 2 * k, 4 * k rides a parameter slider.
Also written: values, level-values
colourAnimatable
multicolour (the default) strokes each level along the full spectrum by its own value, violet low to red high; temperature is the blue → white → red ramp; any ordinary hue draws every ring alike. Both ramps are fixed colours, identical in light and dark mode.
blueredorangeyellowtealgreenpinkpurplegreyhex(…)rgb(…)multicolourtemperature
Also written: color
Defaultmulticolour
widthAnimatable
Stroke width.
Default1.5
opacityAnimatable
How heavy the lines sit over the marks beneath them.
Default1
hiddenAnimatable
Declared but not drawn — animatable, so hidden: true !cue.to{false}(at: 2) is its reveal.
Defaultfalse
lock
A reader may not edit it on an editable graph.
Also written: locked
Defaultfalse
layerAnimatable
Paint order among the marks: a higher layer is drawn later, on top; equal or omitted, the marks stack in document order (later on top). Written z: before the argand plane took that letter for its coordinate.

#Derived attributes

Computed while the element renders — read one with #id.name in attribute position or {{#id.name}} in prose, never set.

minDerived
The smallest value the surface takes over the sampled window — for a loss surface, the number the whole picture is about. Cite it with {{#id.min}}.
maxDerived
The largest value the surface takes over the sampled window.

#Allowed in

#Examples

Teal contours of the saddle x² − y² at −4, −1, 0, 1 and 4: two families of hyperbolas crossing at the origin.Teal contours of the saddle x² − y² at −4, −1, 0, 1 and 4: two families of hyperbolas crossing at the origin.
canvas.graph{
    contour(expression: x^2 - y^2; at: -4, -1, 0, 1, 4; colour: teal)
}(
    x-domain: [-4, 4]
    y-domain: [-4, 4]
)
Four circles about the origin at levels 1, 2, 4 and 8, each further from the last.Four circles about the origin at levels 1, 2, 4 and 8, each further from the last.
canvas.graph{
    contour(expression: x^2 + y^2; at: 1, 2, 4, 8)
}(
    x-domain: [-4, 4]
    y-domain: [-4, 4]
)
Fourteen contours of sin x · cos y on the blue-to-red temperature ramp, closed rings around each peak and trough.Fourteen contours of sin x · cos y on the blue-to-red temperature ramp, closed rings around each peak and trough.
canvas.graph{
    contour(expression: sin(x) * cos(y); levels: 14; colour: temperature)
}

Last updated