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
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Chart title |
categories | list[str] | required | Category labels |
values | list[float] | required | Flat list of all category samples |
color_hex | int | 0x6366F1 | Single fill color |
palette | list[int] | None | None | Per-category colors |
width | int | 900 | Canvas width |
height | int | 480 | Canvas height |
x_label | str | "" | X-axis label |
y_label | str | "" | Y-axis label |
gridlines | bool | True | Horizontal gridlines |
bandwidth | float | 1.0 | KDE 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ètre | Type | Défaut | Description |
|---|---|---|---|
title | str | requis | Titre du graphique |
categories | list[str] | requis | Étiquettes des catégories |
values | list[float] | requis | Liste plate de tous les échantillons par catégorie |
color_hex | int | 0x6366F1 | Couleur de remplissage unique |
palette | list[int] | None | None | Couleurs par catégorie |
width | int | 900 | Largeur du canvas |
height | int | 480 | Hauteur du canvas |
x_label | str | "" | Étiquette de l'axe X |
y_label | str | "" | Étiquette de l'axe Y |
gridlines | bool | True | Lignes de grille horizontales |
bandwidth | float | 1.0 | Multiplicateur 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],
)