Grid¶
Grid value class for gridline configuration.
Ferrum — a statistical visualization library with a Rust core.
Grid
dataclass
¶
Theme-level grid configuration controlling major and minor gridlines.
Accepted by Theme(grid=...) / Theme.update(grid=fr.Grid(...)).
Passing a bare bool remains valid (maps to the major enable flag).
Shorthand resolution. The bare color, width, dash, and
opacity parameters are a fallback that sets both levels. An explicit
major_* or minor_* value for that property overrides the bare value
for that level only. Examples::
Grid(color="#f5f5f5")
# → major_grid_color="#f5f5f5", minor_grid_color="#f5f5f5"
Grid(color="#eee", minor_color="#f8f8f8")
# → major_grid_color="#eee", minor_grid_color="#f8f8f8"
The bare shorthand keys (color, width, dash, opacity) are
never emitted to the Rust renderer; only resolved per-level keys appear
in to_spec_dict() output.
Minor gridlines. minor=True renders minor gridlines on continuous
axes (linear, log, time, pow, sqrt, symlog). On categorical or
discretising axes (band, ordinal, quantile, threshold, bin-ordinal) there
is no continuum to subdivide, so minor=True there is a semantic
absence — no extra lines are drawn and no error is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major
|
bool
|
Enable major gridlines. |
True
|
minor
|
bool
|
Enable minor gridlines (continuous scales only). |
False
|
color
|
str
|
Fallback color for both major and minor gridlines. |
None
|
width
|
float
|
Fallback stroke width for both levels. |
None
|
dash
|
list of float
|
Fallback dash pattern (SVG stroke-dasharray lengths) for both levels. |
None
|
opacity
|
float
|
Fallback stroke opacity for both levels. |
None
|
major_color
|
str
|
Major gridline color; overrides bare |
None
|
minor_color
|
str
|
Minor gridline color; overrides bare |
None
|
major_width
|
float
|
Major gridline stroke width; overrides bare |
None
|
minor_width
|
float
|
Minor gridline stroke width; overrides bare |
None
|
major_dash
|
list of float
|
Major gridline dash pattern; overrides bare |
None
|
minor_dash
|
list of float
|
Minor gridline dash pattern; overrides bare |
None
|
major_opacity
|
float
|
Major gridline opacity; overrides bare |
None
|
minor_opacity
|
float
|
Minor gridline opacity; overrides bare |
None
|
Examples:
>>> import ferrum as fm
>>> # Enable minor gridlines, both levels same colour
>>> g = fm.Grid(minor=True, color="#f5f5f5")
>>> g.to_spec_dict()
{'grid': True, 'minor': True, 'major_grid_color': '#f5f5f5', 'minor_grid_color': '#f5f5f5'}
>>> # Different colours per level
>>> g2 = fm.Grid(minor=True, color="#eeeeee", minor_color="#f8f8f8")
>>> g2.to_spec_dict()
{'grid': True, 'minor': True, 'major_grid_color': '#eeeeee', 'minor_grid_color': '#f8f8f8'}
to_spec_dict ¶
Serialize to the dict shape the Rust binding expects.
Always emits grid (major enable) and minor (minor enable).
Resolves shorthand → per-level: for each of color/width/dash/opacity,
major level = major_X if not None else bare X; minor level =
minor_X if not None else bare X. Only non-None resolved
per-level styling keys are emitted. The bare shorthand keys are
never present in the output.