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

Violin Chart

Signature

sp.build_violin(
    title: str,
    categories: list[str],
    values: list[float],
    *,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    background: str | None = None,
    gridlines: bool = True,
    bandwidth: float = 1.0,
) -> Chart

Aliases: sp.violin


Description

Violin chart combining KDE density estimation with box-plot summary. The mirrored shape shows the full probability distribution of each group.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
categorieslist[str]requiredCategory labels
valueslist[float]requiredFlat list of all category samples
color_hexint0x6366F1Single fill color
palettelist[int] | NoneNonePer-category colors
widthint900Canvas width
heightint480Canvas height
x_labelstr""X-axis label
y_labelstr""Y-axis label
gridlinesboolTrueHorizontal gridlines
bandwidthfloat1.0KDE smoothing bandwidth multiplier

Returns

Chart


Examples

Comparing salary distributions

import seraplot as sp
import random
roles = {
    "Engineer": [random.gauss(95000, 15000) for _ in range(60)],
    "Manager":  [random.gauss(110000, 20000) for _ in range(60)],
    "Analyst":  [random.gauss(75000, 12000) for _ in range(60)],
}
chart = sp.build_violin(
    "Salary Distribution by Role",
    categories=list(roles.keys()),
    values=[v for g in roles.values() for v in g],
    y_label="Salary ($)",
    palette=[0x6366f1, 0x22d3ee, 0xf43f5e],
)
const sp = require('seraplot');
import random
const roles = {
    "Engineer": [random.gauss(95000, 15000) for _ in range(60)],
    "Manager":  [random.gauss(110000, 20000) for _ in range(60)],
    "Analyst":  [random.gauss(75000, 12000) for _ in range(60)],
}
const chart = sp.build_violin("Salary Distribution by Role",
list(roles.keys()),
{
    values: [v for g in roles.values() for v in g],
    y_label: "Salary ($)",
    palette: [0x6366f1, 0x22d3ee, 0xf43f5e]
})
import * as sp from 'seraplot';
import random
const roles = {
    "Engineer": [random.gauss(95000, 15000) for _ in range(60)],
    "Manager":  [random.gauss(110000, 20000) for _ in range(60)],
    "Analyst":  [random.gauss(75000, 12000) for _ in range(60)],
}
const chart = sp.build_violin("Salary Distribution by Role",
list(roles.keys()),
{
    values: [v for g in roles.values() for v in g],
    y_label: "Salary ($)",
    palette: [0x6366f1, 0x22d3ee, 0xf43f5e]
})
▶ Live Preview

See also

Signature

sp.build_violin(
    title: str,
    categories: list[str],
    values: list[float],
    *,
    width: int = 900,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    color_hex: int = 0x6366F1,
    palette: list[int] | None = None,
    background: str | None = None,
    gridlines: bool = True,
    bandwidth: float = 1.0,
) -> Chart

Aliases: sp.violin


Description

Graphique en violon combinant estimation KDE et résumé de boîte à moustaches. La forme en miroir montre la distribution complète de chaque groupe.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
categorieslist[str]requisÉtiquettes des catégories
valueslist[float]requisListe plate de tous les échantillons par catégorie
color_hexint0x6366F1Couleur de remplissage unique
palettelist[int] | NoneNoneCouleurs par catégorie
widthint900Largeur du canvas
heightint480Hauteur du canvas
x_labelstr""Étiquette de l'axe X
y_labelstr""Étiquette de l'axe Y
gridlinesboolTrueLignes de grille horizontales
bandwidthfloat1.0Multiplicateur de bande passante KDE

Retourne

Chart


Exemples

Comparaison des distributions de salaires

import seraplot as sp
import random

postes = {
    "Ingénieur":  [random.gauss(95000, 15000) for _ in range(60)],
    "Manager":    [random.gauss(110000, 20000) for _ in range(60)],
    "Analyste":   [random.gauss(75000, 12000) for _ in range(60)],
}

chart = sp.build_violin(
    "Distribution des salaires par poste",
    categories=list(postes.keys()),
    values=[v for g in postes.values() for v in g],
    y_label="Salaire (€)",
    palette=[0x6366f1, 0x22d3ee, 0xf43f5e],
)

Voir aussi