Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chart methods

Chart methods & global config

Every Chart object returned by SeraPlot supports the same fluent API. Set defaults once with sp.config() and tweak per chart with chainable methods. All methods return a new Chart, so chaining is always safe.

Fluent APIGlobal + per-chart override60+ chart typesDoc-as-code: every card below is generated from the Rust source

Set defaults once. Every chart created afterwards inherits this configuration automatically.

💾Persist aliases across sessions
sp.config.add_alias("bar", "barchart")
sp.config.add_alias("line", "linechart")
sp.config.save()  # writes to ~/.seraplot/config.json
import seraplot as sp  # aliases are auto-loaded from ~/.seraplot/config.json

Curated presets that combine palette, background and gridlines.

ThemeMood
"dark"High-contrast dark dashboard
"light"Soft pastel light backdrop
"scientific"Publication-style monochrome
"apple"Glassy iOS-inspired palette
"notion"Calm Notion-style neutrals
"minimal"Bare lines, no chrome
"neon"Vibrant cyberpunk neons
sp.config(theme=...)global
Apply a theme globally to all charts created after this call. Combine with any other config keys.
sp.config(theme="dark", gridlines=True, font="Inter")
chart = sp.bar("Sales", labels=["Q1","Q2","Q3"], values=[120,180,150])
chart.show()
Tip: Call sp.reset_theme() to return to the framework default at any point.
3

Chart methods

Generated from #[sera_doc] in the Rust source

Every card below is generated straight from the #[sera_doc(...)] annotation on the matching Rust method — name, parameters and description always match the actual implementation.

.html  propertyread-only
Read the full HTML payload as a string.
src = chart.html
len(chart) → intproperty
Returns the size of the HTML payload in bytes.
print(len(chart))
bool(chart) → boolproperty
True when the chart has rendered output.
if chart:
    chart.show()
5

Annotations (cross-chart)

SVG overlays inherited by every plot

annotations=[...] (kwarg)newglobal
Pass a list of annotation dicts to any chart builder. Coordinates default to fractional canvas space (0.0–1.0); set "frac": false to use raw pixels. Supported kind: "hline", "vline", "line", "arrow", "rect", "text".
chart = sp.line(
    "Sales", labels=months, values=sales,
    annotations=[
        {"kind":"hline", "y":0.5, "color":"#22c55e", "dash":"6 4", "text":"Target"},
        {"kind":"vline", "x":0.62, "color":"#f59e0b", "text":"Launch"},
        {"kind":"rect",  "x":0.05, "y":0.65, "x2":0.40, "y2":0.92,
                         "color":"#6366f1", "fill":"#6366f1", "opacity":0.10},
        {"kind":"arrow", "x":0.45, "y":0.30, "x2":0.85, "y2":0.18, "color":"#ef4444"},
        {"kind":"text",  "x":0.46, "y":0.28, "text":"Outlier", "color":"#ef4444"},
    ],
)
Annotation fields
Every annotation accepts the same shape:
FieldTypeDefaultDescription
kindstrrequiredhline / vline / line / arrow / rect / text
x, yfloat0.5Anchor point (frac of canvas if frac=True, pixels otherwise)
x2, y2float1.0End point for line / arrow / rect
colorstr"#ef4444"Stroke / text color (CSS)
fillstr"none"Fill color (rect only)
stroke_widthfloat1.5Stroke width
dashstr""SVG dash array, e.g. "6 4"
opacityfloat1.00.0 - 1.0
textstrNoneOptional label rendered next to the primitive
font_sizefloat11.0Label font size
fracbooltrueCoordinate space: fractional (0-1) or pixel
Tip: Annotations apply uniformly to every 2D and 3D chart through the apply_annotations() hook - no per-chart wiring required.
6

Composers (Grid + Slideshow)

Group charts into stories

sp.grid() alias: sp.build_grid

Compose any number of pre-built charts into a responsive CSS-grid, each chart isolated in its own iframe.

chartslist[Chart]Charts to arrange
colsint = 3Number of columns
gapint = 16Gap between cells in px
bg_colorstrGrid background
titlestr = ""Optional header title
cell_heightint | NoneOverride each cell height
bar  = sp.bar("Sales", labels=["Q1","Q2","Q3","Q4"], values=[120,180,150,210])
line = sp.line("Trend", labels=months, values=sales)
pie  = sp.pie("Mix", labels=["A","B","C"], values=[40,35,25])
sp.grid([bar, line, pie], cols=3, gap=14, title="Dashboard").show()
sp.build_slideshow() navigable HTML carousel

Build a navigable HTML carousel with prev / next buttons and an auto-advance progress bar — tell a story without a slide deck.

chartslist[Chart]Ordered slide list
interval_msint = 2500Auto-advance delay in ms
titlestr = ""Carousel title
widthint = 900Output width in px
heightint = 520Output height in px
slides = [sp.bar(f"Slide {i+1}", labels=["A","B"], values=[i, i+1]) for i in range(4)]
sp.build_slideshow(slides, interval_ms=2200, title="Quarterly Story").show()