Title¶
Title value class for figure titles.
Ferrum — a statistical visualization library with a Rust core.
Title
dataclass
¶
Chart title with optional subtitle.
Accepted on a leaf Chart's title= -- Chart(title=...) /
Chart.properties(title=...) -- with every field here (subtitle,
anchor, offset, font, color) honored: a leaf's ChartSpec.title is a
full TitleSpec.
On a composition's figure-level title=/subtitle=/caption=
(HConcatChart/VConcatChart/ConcatChart/JointChart/
RepeatChart/ClusterMapChart/LayerChart), the composite-tree
render entry's wire chrome fields are bare strings with no
subtitle/styling slot of their own, so a Title passed to any of the
three is normalized at .properties(): a text-only Title (no
field but .text set away from default) reduces to its .text;
title=fm.Title(text=..., subtitle=...) on the six views with a
separate figure-subtitle slot ROUTES the Title's own subtitle
into that slot -- unless an explicit subtitle= is also given in
the same call, which raises ValueError naming both spellings; and a
Title carrying any other field this composite genuinely cannot
express (anchor, offset, font_size, font_weight,
color, subtitle_font_size, subtitle_color on any of the
three keys; subtitle itself on subtitle=/caption=, or on
LayerChart's title=, which has no separate subtitle slot) raises
ValueError at .properties() time rather than silently dropping
it (2026-09-11, batch-H close cycle 3, made lossless and widened to all
three chrome keys in cycle 4; see ferrum-spec.md §3.16's dated
notes). Passing a bare string is equivalent to Title(text=string)
everywhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Primary title text. |
required |
subtitle
|
str
|
Secondary line below the title; |
None
|
anchor
|
('start', 'middle', 'end')
|
Horizontal anchor. |
"start"
|
offset
|
float
|
Pixel offset from plot area; defaults to the theme's |
None
|
font_size
|
float
|
Title font size in points. |
None
|
font_weight
|
str
|
Title font weight (e.g. |
None
|
color
|
str
|
Title color as a CSS color string. |
None
|
subtitle_font_size
|
float
|
Subtitle font size; defaults to |
None
|
subtitle_color
|
str
|
Subtitle color; defaults to the theme's |
None
|
Examples:
>>> import ferrum as fm
>>> title = fm.Title("My Chart", subtitle="subtitle text", anchor="start")
>>> fm.Chart(df).mark_point().encode(x="x", y="y").properties(title=title)
to_spec_dict ¶
Serialize to the dict shape the Rust binding expects.
Only emits non-default fields so the JSON sent to Rust stays minimal and forward-compatible.