geom-function
Polyline of fun(x) sampled uniformly across the x-range.
The trained x-domain is used by default; pass xlim to override it. n samples are taken across that range. Sampled points where fun returns none are dropped silently.
Usage
geom-function(
fun: none,
n: 101,
xlim: none,
stroke: 0.8pt,
colour: auto,
alpha: auto,
linetype: "solid",
inherit-aes: false,
)Parameters
| Parameter | Default | Description |
|---|---|---|
fun |
none |
Callable taking a numeric x and returning a numeric y, or none to skip. |
n |
101 |
Number of samples taken uniformly across the x-range. |
xlim |
none |
Optional (lo, hi) overriding the trained x-domain. |
stroke |
0.8pt |
Line thickness (a Typst length). |
colour |
auto |
Fixed line colour. auto falls back to the theme ink. |
alpha |
auto |
Line opacity in [0, 1]. |
linetype |
"solid" |
Dash keyword. Defaults to "solid". |
inherit-aes |
false |
Whether to merge the plot-level mapping into this layer’s mapping. Defaults to false. |
Returns
Layer dictionary consumed by plot.
Examples
Sine curve sampled across the trained x-domain.
#let frame = ((x: -calc.pi, y: -1), (x: calc.pi, y: 1))
#plot(
data: frame,
mapping: aes(x: "x", y: "y"),
layers: (
geom-blank(),
geom-function(fun: x => calc.sin(x)),
),
width: 10cm,
height: 6cm,
)Pass xlim to override the domain when the training data does not match the function’s natural range.
#let frame = ((x: 0, y: 0), (x: 1, y: 1))
#plot(
data: frame,
mapping: aes(x: "x", y: "y"),
layers: (
geom-blank(),
geom-function(
fun: x => calc.sin(x) * 0.5 + 0.5,
xlim: (0, 4 * calc.pi),
n: 201,
),
),
width: 10cm,
height: 6cm,
)