ferrum.themes¶
Theme class, built-in named themes, and default-theme controls.
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.
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 text styling for body text (axis titles, etc.). |
required |
font_weight
|
optional
|
Default text styling for body text (axis titles, etc.). |
required |
font_color
|
optional
|
Default text styling for body text (axis titles, etc.). |
required |
font_size
|
optional
|
Default text styling for body text (axis titles, etc.). |
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. Fall back to |
required |
label_color
|
optional
|
Tick label styling. Fall back to |
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 |
strip_background_color
|
optional
|
Facet strip-title background color. |
required |
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. Rust sees a fully-resolved dict; no Option fallback chains in
the binding.
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:
get_default_theme ¶
Return the current process-default theme.
Returns:
| Type | Description |
|---|---|
Theme
|
The currently active process-default theme. Starts as
|
Examples:
theme_context ¶
Scope a theme to a with block — alias for set_default_theme().
Prefer this spelling over set_default_theme() when the intent is
always context-manager usage (e.g. in tests or notebook cells).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme
|
Theme to activate for the duration of the |
required |
Returns:
| Type | Description |
|---|---|
AbstractContextManager
|
Context manager; restores the prior default on |
Examples: