geom-contour
Contour-line layer: marching-squares iso-lines over a regular (x, y, z) grid. Pair with a continuous colour scale on _level to shade by height.
bins, binwidth, and breaks control level placement (precedence breaks > binwidth > bins).
Usage
geom-contour(
mapping: none,
data: none,
bins: 10,
binwidth: none,
breaks: auto,
stroke: 0.6pt,
colour: auto,
alpha: auto,
linetype: auto,
inherit-aes: true,
)Parameters
| Parameter | Default | Description |
|---|---|---|
mapping |
none |
Layer-specific aesthetic mapping built with aes. Must map x, y, and z. |
data |
none |
Layer-specific dataset. Falls back to the plot data when none. |
bins |
10 |
Target contour-level count. |
binwidth |
none |
Fixed step between levels. Overrides bins. |
breaks |
auto |
Explicit array of contour levels. Overrides bins and binwidth. |
stroke |
0.6pt |
Line thickness. |
colour |
auto |
Fixed line colour. auto resolves via the colour scale. |
alpha |
auto |
Line opacity in [0, 1]. |
linetype |
auto |
Dash keyword. |
inherit-aes |
true |
Whether to merge the plot-level mapping into this layer’s mapping. |
Returns
Layer dictionary consumed by plot.
Examples
Contour lines over a 30-by-30 grid sampling sin(x) * cos(y).
#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-contour(bins: 10),),
width: 11cm,
height: 7cm,
)