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.
Set defaults once. Every chart created afterwards inherits this configuration automatically.
| Parameter | Type | Default | Effect |
|---|---|---|---|
font | str | system | Font family for every text element |
font_size | int | 12 | Base font size in px |
title_size | int | 16 | Title font size in px |
border_radius | int | 0 | Container border radius (px) |
opacity | float | 1.0 | Element opacity 0.0–1.0 |
responsive | bool | False | Auto-resize to container width |
animation | bool | False | Fade-in animation on chart load |
animation_duration | int | 300 | Animation duration in ms |
crosshair | bool | False | Crosshair lines follow mouse hover |
zoom | bool | False | Mouse wheel zoom + pan (double-click resets) |
tooltip | str | — | Tooltip mode |
locale | str | — | Number formatting locale |
thousands_sep | str | — | Thousands separator character |
margin | int | 0 | Container padding (px) |
export_button | bool | False | Show download button on each chart |
palette | list[int] | — | Color palette as hex ints (e.g. [0x6366F1,0xFB7185]) |
background | str | — | Background color (any CSS color) |
gridlines | bool | False | Show grid lines in chart |
text_auto | bool / str | False | Display values on bars/markers (True raw, or d3 format like ".2s") |
text_position | str | "auto" | "auto" / "inside" / "outside" |
text_angle | int | 0 | Value label rotation (deg) |
text_font_size | int | 12 | Max font size for value labels (px) |
text_font_color | str | — | Value label color |
uniform_text_min_size | int | 0 | Minimum px before label is hidden |
uniform_text_mode | str | "hide" | "hide" small labels or "show" overflow |
bar_corner_radius | int / str | 0 | Bar corner radius in px or "20%" of bar width |
sp.config(**kwargs)globalimport seraplot as sp
sp.config(
font="Inter", font_size=12, title_size=16,
crosshair=True, zoom=True, animation=True,
palette=[0x6366F1, 0xFB7185, 0x10B981],
background="#fafafa", border_radius=8, margin=16,
)
chart = sp.bar("Sales", ["Q1","Q2","Q3"], [100,150,120])
sp.reset_config()globalsp.reset_config()
chart = sp.bar("Clean", labels, values)
Curated presets that combine palette, background and gridlines.
| Theme | Mood |
|---|---|
"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.theme(name)globalsp.config() overrides.sp.theme("dark")
chart = sp.bar("Modern", labels, values)
sp.themes() -> list[str]globalavailable = sp.themes()
print(available)
sp.reset_theme()globalsp.reset_theme()
.set_bg(color=None) -> ChartchainableNone for transparent.chart = sp.line("Trend", x, y).set_bg("#0f172a")
chart = sp.pie("Share", labels, values).set_bg(None)
.set_frame(color=None) -> Chartchainablechart = sp.bar("Title", labels, values).set_frame("transparent")
sp.set_global_background(color)globalsp.set_global_background("#0f172a")
chart1 = sp.bar(...)
chart2 = sp.scatter(...)
sp.reset_global_background()
.show_grid() -> Chartchainablechart = sp.bar("Data", labels, values).show_grid()
.hide_grid() -> Chartchainablechart = sp.bar("Data", labels, values, gridlines=True).hide_grid()
.no_x_axis() -> Chartchainablechart = sp.bar("Y only", labels, values).no_x_axis()
.no_y_axis() -> Chartchainablechart = sp.bar("X only", labels, values).no_y_axis()
.no_axes() -> Chartchainablechart = sp.scatter("Clean", x, y).no_axes()
.no_title() -> Chartchainablechart = sp.pie("Internal", labels, values).no_title()
.no_legend() -> Chartchainablechart = sp.grouped_bar("Q1", cats, series).no_legend()
.title_size(px: int) -> Chartchainablechart = sp.bar("Big", labels, values).title_size(24)
.font(name: str) -> Chartchainablechart = sp.bar("Roboto", labels, values).font("Roboto")
.set_font_size(px: int) -> Chartchainablechart = sp.radar("Skills", labels, values).set_font_size(11)
.text_font(family=None, size=None, color=None) -> Chartchainablechart = sp.bar("Styled", labels, values).text_font(family="Courier", size=11, color="#333")
data-v attributes — bars, lollipops, scatter, pie, treemap, line markers… Format strings follow d3 / Plotly conventions: ".2s", ".0f", ".1%"..text_auto(format=True, position=None, angle=None, font_size=None, color=None) -> Chartchainableformat=True uses raw values; pass a d3 format string for fancy formatting.chart = sp.bar("Raw", labels, values).text_auto(True)
chart = sp.pie("Pct", labels, values).text_auto(".1%", position="outside")
chart = sp.bar("SI", labels, values).text_auto(".2s", angle=45, font_size=13)
.text_position(position: str) -> Chartchainable"auto", "inside", "outside".chart = sp.bar("Out", labels, values).text_position("outside")
.text_angle(degrees: int) -> Chartchainablechart = sp.bar("Rot", labels, values).text_angle(90)
.uniform_text(min_size=8, mode="hide") -> Chartchainablemode="hide" drops labels smaller than min_size; "show" allows overflow.chart = sp.bar("Uniform", labels, values).uniform_text(min_size=10, mode="hide")
.corner_radius_bars(radius) -> Chartchainable"20%" of the bar width.chart = sp.bar("Modern", labels, values).corner_radius_bars(8)
chart = sp.bar("Pct", labels, values).corner_radius_bars("15%")
.animate(duration=300) -> Chartchainablechart = sp.bar("Fade", labels, values).animate(500)
.crosshair() -> Chartchainablechart = sp.scatter("XY", x, y).crosshair()
.zoom() -> Chartchainablechart = sp.line("Big", x, y).zoom()
.no_hover() -> Chartchainablechart = sp.bar("Static", labels, values).no_hover()
.responsive() -> Chartchainablechart = sp.bar("Fluid", labels, values).responsive()
.border_radius(px: int) -> Chartchainablechart = sp.bar("Round", labels, values).border_radius(12)
.set_margin(px: int) -> Chartchainablechart = sp.scatter("Pad", x, y).set_margin(20)
.set_opacity(value: float) -> Chartchainablechart = sp.bar("Faded", labels, values).set_opacity(0.7)
.scale(factor: float) -> Chartchainablechart = sp.pie("Big", labels, values).scale(1.5)
.save(path: str)exportchart.save("chart.html")
.show()exportsp.scatter("Data", x, y).show()
.to_svg() -> strexport<svg> element as a string.svg = chart.to_svg()
.export_svg(path: str)exportchart.export_svg("chart.svg")
.export_png(path: str, scale=2.0)exportcairosvg).chart.export_png("chart.png", scale=1.5)
.export_button() -> Chartchainablechart = sp.pie("Share", labels, values).export_button()
.inject_css(css: str) -> Chartchainable<head>.chart = sp.bar("X", labels, values).inject_css(".sp-ttl{color:#22c55e}")
.inject_js(js: str) -> Chartchainablechart = sp.bar("X", labels, values).inject_js("console.log('loaded')")
.show_labels(position="bottom", labels=None, colors=None) -> Chartchainablechart = sp.bar("Q", labels, values).show_labels(
"top", labels=["Series A", "Series B"], colors=["#6366F1", "#FB7185"]
)
.a11y(title="", desc="") -> Chartchainabletitle and desc for screen readers.chart = sp.bar("Sales", labels, values).a11y(title="Q1–Q4 revenue", desc="Bar chart showing quarterly revenue trends")
.csp_safe() -> Chartchainabledata-* attributes for strict Content-Security-Policy environments.chart = sp.bar("CSP", labels, values).csp_safe()
.downsample(n=2000, method="lttb") -> Chartchainablechart = sp.line("Big", xs, ys).downsample(n=1000)
.diff(other: Chart) -> strchainablea = sp.bar("v1", labels, vals1)
b = sp.bar("v2", labels, vals2)
print(a.diff(b))
.doc() -> strpropertyprint(chart.doc())
.html # propertypropertysrc = chart.html
len(chart) -> intpropertyprint(len(chart))
bool(chart) -> boolpropertyTrue when the chart has rendered output.if chart:
chart.show()
annotations=[...] (kwarg)newglobal0.0 - 1.0); set "frac": false to use raw pixels. Supported kind values: "hline", "vline", "line", "arrow", "rect", "text".chart = sp.build_line_chart(
"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| Field | Type | Default | Description |
|---|---|---|---|
kind | str | required | hline / vline / line / arrow / rect / text |
x, y | float | 0.5 | Anchor point (frac of canvas if frac=True, pixels otherwise) |
x2, y2 | float | 1.0 | End point for line / arrow / rect |
color | str | "#ef4444" | Stroke / text color (CSS) |
fill | str | "none" | Fill color (rect only) |
stroke_width | float | 1.5 | Stroke width |
dash | str | "" | SVG dash array, e.g. "6 4" |
opacity | float | 1.0 | 0.0 - 1.0 |
text | str | None | Optional label rendered next to the primitive |
font_size | float | 11.0 | Label font size |
frac | bool | true | Coordinate space: fractional (0-1) or pixel |
apply_annotations() hook - no per-chart wiring required.sp.grid(charts, cols=3, gap=16, bg_color="#0a0f1c", title="", cell_height=None) -> Chartnewsp.build_grid is an identical alias. cell_height defaults to the chart's own height attribute.bar = sp.build_bar_chart("Q-Sales", labels=["Q1","Q2","Q3","Q4"], values=[120,180,150,210])
line = sp.build_line_chart("Trend", labels=months, values=sales)
pie = sp.build_pie_chart("Mix", labels=["A","B","C"], values=[40,35,25])
grid = sp.grid([bar, line, pie], cols=3, gap=14, title="Dashboard")
grid.show()
sp.build_slideshow(charts, interval_ms=2500, title='', width=900, height=520) -> Chartnewslides = [sp.build_bar_chart(f"Slide {i+1}", labels=["A","B"], values=[i, i+1]) for i in range(4)]
show = sp.build_slideshow(slides, interval_ms=2200, title="Quarterly Story")
show.show()
Méthodes & configuration globale
Tout objet Chart renvoyé par SeraPlot expose la même API fluide. Définis les valeurs par défaut une fois avec sp.config(), ajuste chart par chart avec des méthodes chaînées. Toutes les méthodes retournent un nouveau Chart : le chaînage est toujours sûr.
Définis les défauts une fois. Tous les graphiques créés ensuite héritent automatiquement de cette configuration.
| Paramètre | Type | Défaut | Effet |
|---|---|---|---|
font | str | system | Font family for every text element |
font_size | int | 12 | Base font size in px |
title_size | int | 16 | Title font size in px |
border_radius | int | 0 | Container border radius (px) |
opacity | float | 1.0 | Element opacity 0.0–1.0 |
responsive | bool | False | Auto-resize to container width |
animation | bool | False | Fade-in animation on chart load |
animation_duration | int | 300 | Animation duration in ms |
crosshair | bool | False | Crosshair lines follow mouse hover |
zoom | bool | False | Mouse wheel zoom + pan (double-click resets) |
tooltip | str | — | Tooltip mode |
locale | str | — | Number formatting locale |
thousands_sep | str | — | Thousands separator character |
margin | int | 0 | Container padding (px) |
export_button | bool | False | Show download button on each chart |
palette | list[int] | — | Color palette as hex ints (e.g. [0x6366F1,0xFB7185]) |
background | str | — | Background color (any CSS color) |
gridlines | bool | False | Show grid lines in chart |
text_auto | bool / str | False | Display values on bars/markers (True raw, or d3 format like ".2s") |
text_position | str | "auto" | "auto" / "inside" / "outside" |
text_angle | int | 0 | Value label rotation (deg) |
text_font_size | int | 12 | Max font size for value labels (px) |
text_font_color | str | — | Value label color |
uniform_text_min_size | int | 0 | Minimum px before label is hidden |
uniform_text_mode | str | "hide" | "hide" small labels or "show" overflow |
bar_corner_radius | int / str | 0 | Bar corner radius in px or "20%" of bar width |
sp.config(**kwargs)globalimport seraplot as sp
sp.config(
font="Inter", font_size=12, title_size=16,
crosshair=True, zoom=True, animation=True,
palette=[0x6366F1, 0xFB7185, 0x10B981],
background="#fafafa", border_radius=8, margin=16,
)
chart = sp.bar("Sales", ["Q1","Q2","Q3"], [100,150,120])
sp.reset_config()globalsp.reset_config()
chart = sp.bar("Clean", labels, values)
Préréglages combinant palette, fond et grille.
| Theme | Mood |
|---|---|
"dark" | Tableau de bord sombre haut contraste |
"light" | Fond clair pastel doux |
"scientific" | Style publication monochrome |
"apple" | Palette inspirée iOS, glassy |
"notion" | Neutres calmes type Notion |
"minimal" | Lignes pures, sans décoration |
"neon" | Néons cyberpunk vibrants |
sp.theme(name)globalsp.config().sp.theme("dark")
chart = sp.bar("Modern", labels, values)
sp.themes() -> list[str]globalavailable = sp.themes()
print(available)
sp.reset_theme()globalsp.reset_theme()
.set_bg(color=None) -> ChartchainableNone pour transparent.chart = sp.line("Trend", x, y).set_bg("#0f172a")
chart = sp.pie("Share", labels, values).set_bg(None)
.set_frame(color=None) -> Chartchainablechart = sp.bar("Title", labels, values).set_frame("transparent")
sp.set_global_background(color)globalsp.set_global_background("#0f172a")
chart1 = sp.bar(...)
chart2 = sp.scatter(...)
sp.reset_global_background()
.show_grid() -> Chartchainablechart = sp.bar("Data", labels, values).show_grid()
.hide_grid() -> Chartchainablechart = sp.bar("Data", labels, values, gridlines=True).hide_grid()
.no_x_axis() -> Chartchainablechart = sp.bar("Y only", labels, values).no_x_axis()
.no_y_axis() -> Chartchainablechart = sp.bar("X only", labels, values).no_y_axis()
.no_axes() -> Chartchainablechart = sp.scatter("Clean", x, y).no_axes()
.no_title() -> Chartchainablechart = sp.pie("Internal", labels, values).no_title()
.no_legend() -> Chartchainablechart = sp.grouped_bar("Q1", cats, series).no_legend()
.title_size(px: int) -> Chartchainablechart = sp.bar("Big", labels, values).title_size(24)
.font(name: str) -> Chartchainablechart = sp.bar("Roboto", labels, values).font("Roboto")
.set_font_size(px: int) -> Chartchainablechart = sp.radar("Skills", labels, values).set_font_size(11)
.text_font(family=None, size=None, color=None) -> Chartchainablechart = sp.bar("Styled", labels, values).text_font(family="Courier", size=11, color="#333")
data-v — barres, lollipops, scatter, pie, treemap, marqueurs de ligne… Les formats suivent d3 / Plotly : ".2s", ".0f", ".1%"..text_auto(format=True, position=None, angle=None, font_size=None, color=None) -> Chartchainableformat=True = brut ; passe un format d3 pour personnaliser.chart = sp.bar("Raw", labels, values).text_auto(True)
chart = sp.pie("Pct", labels, values).text_auto(".1%", position="outside")
chart = sp.bar("SI", labels, values).text_auto(".2s", angle=45, font_size=13)
.text_position(position: str) -> Chartchainable"auto", "inside", "outside".chart = sp.bar("Out", labels, values).text_position("outside")
.text_angle(degrees: int) -> Chartchainablechart = sp.bar("Rot", labels, values).text_angle(90)
.uniform_text(min_size=8, mode="hide") -> Chartchainablemode="hide" masque les labels < min_size ; "show" autorise l'overflow.chart = sp.bar("Uniform", labels, values).uniform_text(min_size=10, mode="hide")
.corner_radius_bars(radius) -> Chartchainable"20%" de la largeur de barre.chart = sp.bar("Modern", labels, values).corner_radius_bars(8)
chart = sp.bar("Pct", labels, values).corner_radius_bars("15%")
.animate(duration=300) -> Chartchainablechart = sp.bar("Fade", labels, values).animate(500)
.crosshair() -> Chartchainablechart = sp.scatter("XY", x, y).crosshair()
.zoom() -> Chartchainablechart = sp.line("Big", x, y).zoom()
.no_hover() -> Chartchainablechart = sp.bar("Static", labels, values).no_hover()
.responsive() -> Chartchainablechart = sp.bar("Fluid", labels, values).responsive()
.border_radius(px: int) -> Chartchainablechart = sp.bar("Round", labels, values).border_radius(12)
.set_margin(px: int) -> Chartchainablechart = sp.scatter("Pad", x, y).set_margin(20)
.set_opacity(value: float) -> Chartchainablechart = sp.bar("Faded", labels, values).set_opacity(0.7)
.scale(factor: float) -> Chartchainablechart = sp.pie("Big", labels, values).scale(1.5)
.save(path: str)exportchart.save("chart.html")
.show()exportsp.scatter("Data", x, y).show()
.to_svg() -> strexport<svg> sous forme de chaîne.svg = chart.to_svg()
.export_svg(path: str)exportchart.export_svg("chart.svg")
.export_png(path: str, scale=2.0)exportcairosvg).chart.export_png("chart.png", scale=1.5)
.export_button() -> Chartchainablechart = sp.pie("Share", labels, values).export_button()
.inject_css(css: str) -> Chartchainable<head> du chart.chart = sp.bar("X", labels, values).inject_css(".sp-ttl{color:#22c55e}")
.inject_js(js: str) -> Chartchainablechart = sp.bar("X", labels, values).inject_js("console.log('loaded')")
.show_labels(position="bottom", labels=None, colors=None) -> Chartchainablechart = sp.bar("Q", labels, values).show_labels(
"top", labels=["Series A", "Series B"], colors=["#6366F1", "#FB7185"]
)
.a11y(title="", desc="") -> Chartchainabletitle et desc ARIA pour les lecteurs d'écran.chart = sp.bar("Sales", labels, values).a11y(title="Q1–Q4 revenue", desc="Bar chart showing quarterly revenue trends")
.csp_safe() -> Chartchainabledata-* pour les environnements CSP strict.chart = sp.bar("CSP", labels, values).csp_safe()
.downsample(n=2000, method="lttb") -> Chartchainablechart = sp.line("Big", xs, ys).downsample(n=1000)
.diff(other: Chart) -> strchainablea = sp.bar("v1", labels, vals1)
b = sp.bar("v2", labels, vals2)
print(a.diff(b))
.doc() -> strpropertyprint(chart.doc())
.html # propertypropertysrc = chart.html
len(chart) -> intpropertyprint(len(chart))
bool(chart) -> boolpropertyTrue si le chart a un rendu.if chart:
chart.show()
annotations=[...] (kwarg)nouveauglobal0.0 - 1.0) ; mets "frac": false pour utiliser des pixels. Valeurs supportees pour kind : "hline", "vline", "line", "arrow", "rect", "text".chart = sp.build_line_chart(
"Ventes", labels=mois, values=ventes,
annotations=[
{"kind":"hline", "y":0.5, "color":"#22c55e", "dash":"6 4", "text":"Cible"},
{"kind":"vline", "x":0.62, "color":"#f59e0b", "text":"Lancement"},
{"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"},
],
)
Champs d annotation| Champ | Type | Defaut | Description |
|---|---|---|---|
kind | str | requis | hline / vline / line / arrow / rect / text |
x, y | float | 0.5 | Point d ancrage (frac canvas si frac=True, pixels sinon) |
x2, y2 | float | 1.0 | Point final pour line / arrow / rect |
color | str | "#ef4444" | Couleur de trait / texte (CSS) |
fill | str | "none" | Couleur de remplissage (rect uniquement) |
stroke_width | float | 1.5 | Epaisseur du trait |
dash | str | "" | SVG dash array, ex. "6 4" |
opacity | float | 1.0 | 0.0 - 1.0 |
text | str | None | Etiquette optionnelle a cote du primitif |
font_size | float | 11.0 | Taille de la police de l etiquette |
frac | bool | true | Espace de coordonnees : fractionnaire (0-1) ou pixel |
apply_annotations() - aucun branchement par chart requis.sp.grid(charts, cols=3, gap=16, bg_color="#0a0f1c", title="", cell_height=None) -> Chartnouveausp.build_grid est un alias identique. cell_height utilise par defaut la hauteur detectee dans le chart.bar = sp.build_bar_chart("Ventes-Q", labels=["Q1","Q2","Q3","Q4"], values=[120,180,150,210])
line = sp.build_line_chart("Tendance", labels=mois, values=ventes)
pie = sp.build_pie_chart("Mix", labels=["A","B","C"], values=[40,35,25])
grid = sp.grid([bar, line, pie], cols=3, gap=14, title="Tableau de bord")
grid.show()
sp.build_slideshow(charts, interval_ms=2500, title='', width=900, height=520) -> Chartnouveauslides = [sp.build_bar_chart(f"Slide {i+1}", labels=["A","B"], values=[i, i+1]) for i in range(4)]
show = sp.build_slideshow(slides, interval_ms=2200, title="Histoire trimestrielle")
show.show()