stat-contour

Marching-squares contour statistic.

Treats input rows as samples of a scalar field z over a regular (x, y) grid (one row per Cartesian product cell) and emits the iso-line segments at each level. Pair with geom-path or geom-contour to draw.

Either breaks, binwidth, or bins controls level placement; precedence runs breaks > binwidth > bins (default bins: 10).

Usage

stat-contour(
  bins: 10,
  binwidth: none,
  breaks: auto,
)

Parameters

Parameter Default Description
bins 10 Target contour-level count when breaks and binwidth are unset.
binwidth none Fixed step between levels. Overrides bins.
breaks auto Explicit array of contour levels. Overrides bins and binwidth.

Returns

Statistic object with name: "contour".

Outputs

  • x.
  • y.
  • group.
  • _level.

Examples

Drive geom-path with the constructor form over a sin(x) * cos(y) grid to trace eight iso-lines.

#let n = 30
#let d = ()
#for i in range(n) { for j in range(n) {
  let x = -3 + 6 * i / (n - 1)
  let y = -3 + 6 * j / (n - 1)
  d.push((x: x, y: y, z: calc.sin(x) * calc.cos(y)))
} }
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", z: "z"),
  layers: (geom-path(stat: stat-contour(bins: 8)),),
  width: 10cm,
  height: 6cm,
)

Eight iso-lines tracing levels of sin(x)*cos(y) over a 30-by-30 grid spanning x and y from -3 to 3 via stat-contour driving geom-path.

Eight iso-lines tracing levels of sin(x)*cos(y) over a 30-by-30 grid spanning x and y from -3 to 3 via stat-contour driving geom-path.

See also

geom-contour, stat-bin-2d.

Back to top