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

Multi-Line Chart

Signature

sp.build_multiline_chart(
    title: str,
    x_labels: list[str],
    series_values: list[list[float]],
    *,
    show_points: bool = True,
    series_names: list[str] | None = None,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = 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,
    legend_position: str = "top",
    hover_json: str | None = None,
) -> Chart

Aliases: sp.multiline


Description

Multiple line series plotted on a shared axis. Unlike build_line_chart, this accepts several series in one call.

Each inner list in series_values must have the same length as x_labels.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
x_labelslist[str]requiredShared X-axis tick labels
series_valueslist[list[float]]requiredOne inner list per series
show_pointsboolTrueShow markers at data points
series_nameslist[str] | NoneNoneLegend names for each series
palettelist[int] | NoneNoneCustom hex color per series
widthint900Canvas width
heightint480Canvas height
x_labelstr""X-axis label
y_labelstr""Y-axis label
gridlinesboolTrueHorizontal gridlines
legend_positionstr"top""top", "bottom", "right"
hover_jsonstr | NoneNoneCustom hover tooltip JSON

Returns

Chart


Examples

Monthly revenue by product

import seraplot as sp
months = ["Jan","Feb","Mar","Apr","May","Jun"]
chart = sp.build_multiline_chart(
    "Monthly Revenue by Product",
    x_labels=months,
    series_values=[
        [12200, 13400, 15100, 14800, 16200, 17500],
        [8100,  9200,  9800,  10200, 11000, 12400],
        [3200,  3600,  4100,  4500,  4800,  5200],
    ],
    series_names=["Product A", "Product B", "Product C"],
    show_points=True,
    y_label="Revenue ($)",
)
const sp = require('seraplot');
const months = ["Jan","Feb","Mar","Apr","May","Jun"]
const chart = sp.build_multiline_chart("Monthly Revenue by Product",
months,
{
    series_values: [[12200, 13400, 15100, 14800, 16200, 17500], [8100, 9200, 9800, 10200, 11000, 12400], [3200, 3600, 4100, 4500, 4800, 5200]],
    series_names: ["Product A", "Product B", "Product C"],
    show_points: true,
    y_label: "Revenue ($)"
})
import * as sp from 'seraplot';
const months: string[] = ["Jan","Feb","Mar","Apr","May","Jun"]
const chart = sp.build_multiline_chart("Monthly Revenue by Product",
months,
{
    series_values: [[12200, 13400, 15100, 14800, 16200, 17500], [8100, 9200, 9800, 10200, 11000, 12400], [3200, 3600, 4100, 4500, 4800, 5200]],
    series_names: ["Product A", "Product B", "Product C"],
    show_points: true,
    y_label: "Revenue ($)"
})
▶ Live Preview

See also

Signature

sp.build_multiline_chart(
    title: str,
    x_labels: list[str],
    series_values: list[list[float]],
    *,
    show_points: bool = True,
    series_names: list[str] | None = None,
    color_hex: int = 0x6366F1,
    palette: list[int] | None = 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,
    legend_position: str = "top",
    hover_json: str | None = None,
) -> Chart

Aliases: sp.multiline


Description

Graphique multi-courbes — plusieurs séries tracées sur un axe commun. Chaque liste dans series_values doit avoir la même longueur que x_labels.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
x_labelslist[str]requisÉtiquettes de l'axe X commun
series_valueslist[list[float]]requisUne liste par série
show_pointsboolTrueAfficher les marqueurs aux points de données
series_nameslist[str] | NoneNoneNoms des séries pour la légende
palettelist[int] | NoneNoneCouleurs personnalisées par série
widthint900Largeur du canvas
heightint480Hauteur du canvas
x_labelstr""Étiquette de l'axe X
y_labelstr""Étiquette de l'axe Y
gridlinesboolTrueLignes de grille horizontales
legend_positionstr"top""top", "bottom", "right"
hover_jsonstr | NoneNoneJSON d'infobulle personnalisée

Retourne

Chart


Exemples

import seraplot as sp

mois = ["Jan","Fév","Mar","Avr","Mai","Jun"]

chart = sp.build_multiline_chart(
    "Chiffre d'affaires mensuel par produit",
    x_labels=mois,
    series_values=[
        [12200, 13400, 15100, 14800, 16200, 17500],
        [8100,  9200,  9800,  10200, 11000, 12400],
        [3200,  3600,  4100,  4500,  4800,  5200],
    ],
    series_names=["Produit A", "Produit B", "Produit C"],
    show_points=True,
    y_label="Chiffre d'affaires (€)",
)

Voir aussi