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

Lollipop Chart

Signature

sp.build_lollipop_chart(
    title: str,
    labels: list[str],
    values: list[float],
    *,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    orientation: str = "v",
    show_text: bool = False,
    sort_order: str = "none",
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    gridlines: bool = True,
    background: str | None = None,
    no_x_axis: bool = False,
    no_y_axis: bool = False,
) -> Chart

Aliases: sp.lollipop


Description

Lollipop chart — a cleaner alternative to bar charts using a thin stem and a circle at the end. Reduces ink-to-data ratio compared to filled bars.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
labelslist[str]requiredCategory labels
valueslist[float]requiredValues per category
color_hexint0x6366F1Stem and dot color
palettelist[int] | NoneNonePer-category colors
orientationstr"v""v" (vertical) or "h" (horizontal)
show_textboolFalseShow value labels
sort_orderstr"none""asc", "desc", or "none"
widthint900Canvas width
heightint480Canvas height
x_labelstr""X-axis label
y_labelstr""Y-axis label
gridlinesboolTrueShow gridlines

Returns

Chart


Examples

Sorted lollipop

import seraplot as sp
chart = sp.build_lollipop_chart(
    "Top Countries by GDP per Capita",
    labels=["Luxembourg", "Switzerland", "USA", "Germany", "France"],
    values=[135605, 92434, 76398, 50802, 42409],
    orientation="h",
    sort_order="desc",
    show_values=True,
    x_label="GDP per capita ($)",
)
const sp = require('seraplot');
const chart = sp.build_lollipop_chart("Top Countries by GDP per Capita",
["Luxembourg", "Switzerland", "USA", "Germany", "France"],
{
    values: [135605, 92434, 76398, 50802, 42409],
    orientation: "h",
    sort_order: "desc",
    show_values: true,
    x_label: "GDP per capita ($)"
})
import * as sp from 'seraplot';
const chart = sp.build_lollipop_chart("Top Countries by GDP per Capita",
["Luxembourg", "Switzerland", "USA", "Germany", "France"],
{
    values: [135605, 92434, 76398, 50802, 42409],
    orientation: "h",
    sort_order: "desc",
    show_values: true,
    x_label: "GDP per capita ($)"
})
▶ Live Preview

See also

Signature

sp.build_lollipop_chart(
    title: str,
    labels: list[str],
    values: list[float],
    *,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    orientation: str = "v",
    show_text: bool = False,
    sort_order: str = "none",
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    gridlines: bool = True,
    background: str | None = None,
    no_x_axis: bool = False,
    no_y_axis: bool = False,
) -> Chart

Aliases: sp.lollipop


Description

Graphique en sucette — alternative épurée aux barres avec une tige fine et un cercle au bout. Réduit le ratio encre/données par rapport aux barres remplies.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
labelslist[str]requisÉtiquettes des catégories
valueslist[float]requisValeurs par catégorie
color_hexint0x6366F1Couleur de la tige et du point
palettelist[int] | NoneNoneCouleurs par catégorie
orientationstr"v""v" (vertical) ou "h" (horizontal)
show_textboolFalseAfficher les étiquettes de valeur
sort_orderstr"none""asc", "desc" ou "none"
widthint900Largeur du canvas
heightint480Hauteur du canvas
x_labelstr""Étiquette de l'axe X
y_labelstr""Étiquette de l'axe Y
gridlinesboolTrueAfficher les lignes de grille

Retourne

Chart


Exemples

import seraplot as sp

chart = sp.build_lollipop_chart(
    "Top pays par PIB par habitant",
    labels=["Luxembourg", "Suisse", "USA", "Allemagne", "France"],
    values=[135605, 92434, 76398, 50802, 42409],
    orientation="h",
    sort_order="desc",
    show_text=True,
    x_label="PIB par habitant ($)",
)

Voir aussi