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

Slope Chart

Signature

sp.build_slope(
    title: str,
    labels: list[str],
    values_left: list[float],
    values_right: list[float],
    left_label: str,
    right_label: str,
    *,
    show_text: bool = True,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    width: int = 600,
    height: int = 480,
    background: str | None = None,
) -> Chart

Aliases: sp.slope


Description

Slope chart comparing two values per entity (before/after, period A vs B). Parallel vertical axes are connected by slope lines — rising or falling.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
labelslist[str]requiredEntity names (one per line)
values_leftlist[float]requiredValues on the left axis
values_rightlist[float]requiredValues on the right axis
left_labelstrrequiredLeft axis label (e.g. "2020")
right_labelstrrequiredRight axis label (e.g. "2024")
show_textboolTrueShow values next to endpoints
color_hexint0x6366F1Line color (single)
palettelist[int] | NoneNonePer-entity line colors
widthint600Canvas width
heightint480Canvas height
backgroundstr | NoneNoneChart background

Returns

Chart


Examples

Country ranking change

import seraplot as sp
chart = sp.build_slope(
    "HDI Change 2000 to 2023",
    labels=["Germany", "Japan", "Brazil", "India", "Nigeria"],
    values_left=[0.926, 0.909, 0.694, 0.493, 0.452],
    values_right=[0.950, 0.920, 0.760, 0.644, 0.548],
    left_label="2000",
    right_label="2023",
    show_text=True,
)
const sp = require('seraplot');
const chart = sp.build_slope("HDI Change 2000 to 2023",
["Germany", "Japan", "Brazil", "India", "Nigeria"],
[0.926, 0.909, 0.694, 0.493, 0.452],
{
    values_right: [0.950, 0.920, 0.760, 0.644, 0.548],
    left_label: "2000",
    right_label: "2023",
    show_text: true
})
import * as sp from 'seraplot';
const chart = sp.build_slope("HDI Change 2000 to 2023",
["Germany", "Japan", "Brazil", "India", "Nigeria"],
[0.926, 0.909, 0.694, 0.493, 0.452],
{
    values_right: [0.950, 0.920, 0.760, 0.644, 0.548],
    left_label: "2000",
    right_label: "2023",
    show_text: true
})
▶ Live Preview

See also

Signature

sp.build_slope(
    title: str,
    labels: list[str],
    values_left: list[float],
    values_right: list[float],
    left_label: str,
    right_label: str,
    *,
    show_text: bool = True,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    width: int = 600,
    height: int = 480,
    background: str | None = None,
) -> Chart

Aliases: sp.slope


Description

Graphique de pente comparant deux valeurs par entité (avant/après, période A vs B). Les axes verticaux parallèles sont reliés par des lignes de pente montantes ou descendantes.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
labelslist[str]requisNoms des entités (une par ligne)
values_leftlist[float]requisValeurs sur l'axe gauche
values_rightlist[float]requisValeurs sur l'axe droit
left_labelstrrequisTitre de l'axe gauche (ex. "2020")
right_labelstrrequisTitre de l'axe droit (ex. "2024")
show_textboolTrueAfficher les valeurs aux extrémités
color_hexint0x6366F1Couleur des lignes (unique)
palettelist[int] | NoneNoneCouleurs par entité
widthint600Largeur du canvas
heightint480Hauteur du canvas
backgroundstr | NoneNoneCouleur de fond

Retourne

Chart


Exemples

import seraplot as sp

chart = sp.build_slope(
    "IDH : Évolution 2000–2023",
    labels=["Allemagne", "Japon", "Brésil", "Inde", "Nigéria"],
    values_left=[0.926, 0.909, 0.694, 0.493, 0.452],
    values_right=[0.950, 0.920, 0.760, 0.644, 0.548],
    left_label="2000",
    right_label="2023",
    show_text=True,
)

Voir aussi