Themes¶
Built-in themes and Theme / set_default_theme / theme_context.
Ferrum — a statistical visualization library with a Rust core.
Theme ¶
Immutable theme value class for chart styling.
Pass to Chart.theme(t) per-chart or activate process-wide via
set_default_theme(t). Per-chart .theme() always wins at render
time.
Cascade behavior: Chart.theme(t) replaces the entire active theme
with t — it does not merge individual keys. To override a subset of
keys on top of an existing theme, use Theme.update()::
base = fm.themes.paper_ink
custom = base.update(grid=False, padding=20)
chart.theme(custom)
All keys listed in ferrum-spec.md §3.13 are plumbed end-to-end to
the Rust renderer. Unknown keys raise ValueError at construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
background
|
str
|
Chart background color as a CSS hex string (e.g. |
required |
mark_color
|
str
|
Default mark fill/stroke color for marks that have no explicit color encoding. |
required |
font_family
|
optional
|
Default body-text styling. |
required |
font_weight
|
optional
|
Default body-text styling. |
required |
font_color
|
optional
|
Default body-text styling. |
required |
font_size
|
optional
|
Default body-text styling. |
required |
title_font_family
|
optional
|
Chart title styling. |
required |
title_font_size
|
optional
|
Chart title styling. |
required |
title_font_weight
|
optional
|
Chart title styling. |
required |
title_color
|
optional
|
Chart title styling. |
required |
title_anchor
|
optional
|
Chart title styling. |
required |
title_offset
|
optional
|
Chart title styling. |
required |
label_font_family
|
optional
|
Tick label styling (see the "Fallbacks" list below). |
required |
label_color
|
optional
|
Tick label styling (see the "Fallbacks" list below). |
required |
grid
|
bool
|
Whether to draw grid lines (default True). |
required |
grid_color
|
optional
|
Grid line styling. |
required |
grid_width
|
optional
|
Grid line styling. |
required |
grid_dash
|
optional
|
Grid line styling. |
required |
grid_opacity
|
optional
|
Grid line styling. |
required |
axis_line
|
bool
|
Whether to draw axis strokes (default True). |
required |
axis_line_color
|
optional
|
Axis and tick styling. |
required |
axis_line_width
|
optional
|
Axis and tick styling. |
required |
tick_color
|
optional
|
Axis and tick styling. |
required |
tick_size
|
optional
|
Axis and tick styling. |
required |
tick_width
|
optional
|
Axis and tick styling. |
required |
point_size
|
optional
|
Mark styling. |
required |
point_opacity
|
optional
|
Mark styling. |
required |
line_stroke_width
|
optional
|
Mark styling. |
required |
bar_corner_radius
|
optional
|
Mark styling. |
required |
area_opacity
|
optional
|
Mark styling. |
required |
opacity
|
optional
|
Mark styling. |
required |
color_scheme
|
str
|
Named categorical palette: one of |
required |
sequential_scheme
|
str
|
Default sequential color ramp used by heatmaps, density plots, and
other continuous-color charts when no explicit |
required |
diverging_scheme
|
str
|
Default diverging color ramp used by correlation matrices and other
diverging-color charts when no explicit |
required |
legend_orient
|
optional
|
Legend layout. |
required |
legend_direction
|
optional
|
Legend layout. |
required |
legend_title_font_size
|
optional
|
Legend layout. |
required |
padding
|
optional
|
Spacing in pixels. |
required |
axis_title_padding
|
optional
|
Spacing in pixels. |
required |
column_padding
|
optional
|
Spacing in pixels. |
required |
row_padding
|
optional
|
Spacing in pixels. |
required |
reference_line_color
|
optional
|
Color and dash pattern for reference / annotation guide lines. |
required |
reference_line_dash
|
optional
|
Color and dash pattern for reference / annotation guide lines. |
required |
strip_background_color
|
optional
|
Facet strip-title background color. |
required |
strip_text_size
|
float
|
Font size for facet strip titles (default 12). |
required |
strip_padding
|
float
|
Vertical padding around facet strip titles (default 6). |
required |
cull_threshold
|
int
|
Minimum number of pixels between adjacent axis tick labels before
culling kicks in. Labels are dropped until the remaining labels are at
least this many pixels apart. Default 8 (set in Rust). Set to |
required |
Fallbacks
When a title_* / label_* key is unset, it falls back to its
body-text counterpart at render time. The pair list below is generated
from Theme._FALLBACKS (the single source of truth):
%(fallbacks)s
Raises:
| Type | Description |
|---|---|
ValueError
|
If any keyword argument is not in the supported key list (see
|
Examples:
>>> import ferrum as fm
>>> t = fm.Theme(background="#f9f9f9", grid=False, padding=16)
>>> t2 = t.update(mark_color="#e74c3c")
>>> t2
Theme(background='#f9f9f9', grid=False, mark_color='#e74c3c', padding=16)
update ¶
Return a new Theme with the given properties overridden.
Passing None for a key removes that property from the derived
theme. The source theme is unchanged (immutable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
any
|
Property overrides. Pass |
{}
|
Returns:
| Type | Description |
|---|---|
Theme
|
A new |
Examples:
to_spec_dict ¶
Return a dict suitable for ferrum._core.render_svg(theme=...).
Resolves spec-defined fallbacks (e.g. title_color falls back to
font_color if unset) and normalises the public Python alias
background to the Rust binding's canonical background_color
key. CSS shorthand hex colors (#rgb / #rgba) are expanded by
the Rust color parser (from_hex_str); Python forwards color
strings unchanged. Rust sees a fully-resolved dict; no Option
fallback chains in the binding.
get_default_theme ¶
Return the current process-default theme.
Returns:
| Type | Description |
|---|---|
Theme
|
The currently active process-default theme. Starts as
|
Examples:
set_default_theme ¶
Set the process-default theme for all subsequent charts.
The returned object is a context manager. Use it with with to scope
the default to a block (previous default is restored on __exit__).
Fire-and-forget usage (without with) is also supported.
Per-chart Chart.theme(t) always overrides this process default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme
|
Theme to install as the process default. |
required |
Returns:
| Type | Description |
|---|---|
AbstractContextManager
|
Context manager that restores the prior default on |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
Fire-and-forget:
Scoped to a block:
theme_context ¶
Context-manager-spelling alias for :func:set_default_theme. See it for full semantics.