ferrum.position¶
Position adjustment strategies for overlapping marks.
Position-adjustment value classes: Identity, Dodge, Jitter, Stack.
Identity ¶
Explicit no-op position adjustment.
Distinct from position=None (which means "no adjustment declared"):
Identity is part of the spec and round-trips through JSON. Use it
when composing layered charts that need to opt out of an inherited stack
or dodge on a per-layer basis.
Eligible marks: all.
Examples:
Dodge ¶
Side-by-side placement of marks grouped by a channel.
Eligible marks: bar, point, box, boxplot, boxen,
swarm, violin, errorbar, errorband, ribbon,
histogram, density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
str
|
Channel name to group by. Defaults to the color/fill channel when omitted. |
None
|
padding
|
float
|
Gap between dodged groups as a fraction of band width. Must be in
|
0.05
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.Chart(df).encode(x="cat", y="val", color="grp").mark_bar(
... position=fm.Dodge()
... )
Jitter ¶
Random per-row noise applied to x, y, or both axes.
Uses a ChaCha8 RNG seeded from seed, making SVG output
byte-deterministic for a given dataset and seed. When seed=None the
Rust renderer derives a per-row seed from the row's data values via
xxh3 — output remains deterministic across runs for fixed inputs.
Eligible marks: point, swarm, tick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
('x', 'y', 'both')
|
Which axis or axes to jitter. |
"x"
|
width
|
float
|
Maximum absolute displacement in scaled units. Must be |
0.4
|
seed
|
int or None
|
RNG seed. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.Chart(df).encode(x="grp", y="value").mark_point(
... position=fm.Jitter(width=0.3, seed=42)
... )
Stack ¶
Vertical accumulation of marks grouped by a channel.
Eligible marks: rect-style (bar, area, ribbon,
histogram, density) and annotation-style (text,
point, rule, tick). The latter sit on top of a
stacked layer to label segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
str
|
Channel name whose distinct values define the stack groups. Defaults to the color/fill channel when omitted. |
None
|
offset
|
('zero', 'normalize', 'center')
|
Stack baseline strategy:
|
"zero"
|
anchor
|
('top', 'mid')
|
Where each row's y output lands within its segment. |
"top"
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.Chart(df).encode(x="year", y="count", color="category").mark_bar(
... position=fm.Stack(offset="normalize")
... )
validate_position_eligibility ¶
Raise TypeError if mark_name does not accept position.
Called by Chart.mark_<name>(position=...) at construction time.
Identity is accepted by every mark; other adjustments are constrained
per the eligibility matrix in this module.