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

Dumbbell Chart

Signature

sp.build_dumbbell(
    title: str,
    labels: list[str],
    values_start: list[float],
    values_end: list[float],
    *,
    show_text: bool = True,
    color_start: int = 0x6366f1,
    color_end: int = 0xf43f5e,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    background: str | None = None,
    gridlines: bool = True,
    hover_json: str | None = None,
) -> Chart

Aliases: sp.dumbbell


Description

Dumbbell chart — a horizontal line connecting two data points per category, ideal for showing the gap or change between two states.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
labelslist[str]requiredCategory labels
values_startlist[float]requiredLeft (start) values
values_endlist[float]requiredRight (end) values
show_textboolTrueShow endpoint value labels
color_startint0x6366f1Start point color
color_endint0xf43f5eEnd point color
widthint900Canvas width
heightint480Canvas height
gridlinesboolTrueVertical gridlines
hover_jsonstr | NoneNoneCustom hover JSON

Returns

Chart


Examples

Life expectancy 2000 vs 2023

import seraplot as sp
chart = sp.build_dumbbell(
    "Life Expectancy: 2000 vs 2023",
    labels=["Japan", "Germany", "Brazil", "India", "Nigeria"],
    values_start=[81.2, 78.1, 70.4, 62.8, 46.5],
    values_end=[84.3, 81.5, 75.2, 70.8, 54.9],
    x_label="Age (years)",
)
const sp = require('seraplot');
const chart = sp.build_dumbbell("Life Expectancy: 2000 vs 2023",
["Japan", "Germany", "Brazil", "India", "Nigeria"],
[81.2, 78.1, 70.4, 62.8, 46.5],
{
    values_end: [84.3, 81.5, 75.2, 70.8, 54.9],
    x_label: "Age (years)"
})
import * as sp from 'seraplot';
const chart = sp.build_dumbbell("Life Expectancy: 2000 vs 2023",
["Japan", "Germany", "Brazil", "India", "Nigeria"],
[81.2, 78.1, 70.4, 62.8, 46.5],
{
    values_end: [84.3, 81.5, 75.2, 70.8, 54.9],
    x_label: "Age (years)"
})
▶ Live Preview

See also

Signature

sp.build_dumbbell(
    title: str,
    labels: list[str],
    values_start: list[float],
    values_end: list[float],
    *,
    show_text: bool = True,
    color_start: int = 0x6366f1,
    color_end: int = 0xf43f5e,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    background: str | None = None,
    gridlines: bool = True,
    hover_json: str | None = None,
) -> Chart

Aliases: sp.dumbbell


Description

Graphique haltère — une ligne horizontale reliant deux valeurs par catégorie, idéal pour montrer l'écart ou l'évolution entre deux états.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
labelslist[str]requisÉtiquettes des catégories
values_startlist[float]requisValeurs de départ (gauche)
values_endlist[float]requisValeurs d'arrivée (droite)
show_textboolTrueAfficher les valeurs aux extrémités
color_startint0x6366f1Couleur du point de départ
color_endint0xf43f5eCouleur du point d'arrivée
widthint900Largeur du canvas
heightint480Hauteur du canvas
gridlinesboolTrueLignes de grille verticales
hover_jsonstr | NoneNoneJSON d'infobulle personnalisée

Retourne

Chart


Exemples

import seraplot as sp

chart = sp.build_dumbbell(
    "Espérance de vie : 2000 vs 2023",
    labels=["Japon", "Allemagne", "Brésil", "Inde", "Nigéria"],
    values_start=[81.2, 78.1, 70.4, 62.8, 46.5],
    values_end=[84.3, 81.5, 75.2, 70.8, 54.9],
    x_label="Âge (ans)",
)

Voir aussi