Skip to content

Layer

Layer and the layer() helper for explicit layering.

Ferrum — a statistical visualization library with a Rust core.

Layer

Single rendering layer inside a multi-layer Chart.

Most multi-layer charts are built via the + operator on two Chart instances (chart1 + chart2). Direct construction of Layer objects is rarely needed outside of ferrum internals and composite-mark expansion code.

Parameters:

Name Type Description Default
data object

DataFrame or Arrow-compatible object for this layer. When None the layer inherits data from the parent ChartSpec.

None
mark str

Mark name (e.g. "point", "line"). None draws a point. Any other non-string value raises ValueError.

None
name str

Identifier for this layer, used by composite-mark expansion and layer-targeted mark overrides. None for unnamed layers.

None
encoding dict

Mapping of channel names to bindings, read as Chart.encode() reads its keyword arguments: a channel object, a shorthand string ("sum(y)", "r:Q", "count()") that means the channel object it spells, or a Repeat placeholder. None leaves the channel unset. An unknown channel name raises ValueError and any other value TypeError, as encode() does. Defaults to an empty dict when omitted. A channel's own condition= kwarg (e.g. fm.Color(field, condition=sel.when(...).otherwise(...))) is honored: Chart.layer() lifts it into the chart's real conditional pipeline, gated by the same vocabulary encode() uses -- a conditional on a channel the wire cannot carry (stroke, shape, x, y) raises the same typed ValueError (2026-09-11, batch-H close cycle 3).

None
transforms list

Must be omitted, None, [] or (). A layer does not run its own transforms: it reads either the chart's final batch or a named chart-level transform's output through its data source. Any other value raises ValueError. To transform one layer's data, give that layer its own chart with .transform(...) and compose it with +, which routes the transform to that layer alone.

None
mark_kwargs dict

Style keyword arguments for the layer's mark (e.g. {"dx": 5, "opacity": 0.7}), held to the fields Rust's style table says the mark draws: aliases (color, alpha) resolve, and a field the mark never draws, a constant size the mark never draws or that is not a finite number above zero, or a malformed value raises ValueError here, voiced as Layer, the call that received it (Layer: keyword argument 'font_size' is not honored by mark_point. Honored: [...]). So does a kwarg only the mark's own method takes (orient on a bar), and a field only ferrum's own code writes (detail, clip, value_axis), each naming the call that sets it.

None

Examples:

>>> from ferrum.layer import Layer
>>> layer = Layer(mark="text", encoding={"x": "x", "y": "y"}, mark_kwargs={"dx": 5})