Histogram
Signature
sp.build_histogram(
title: str,
values: list[float],
*,
color_hex: int = 0,
bins: int = 20,
show_counts: bool = False,
width: int = 900,
height: int = 480,
x_label: str = "",
y_label: str = "",
gridlines: bool = False,
sort_order: str = "none",
hover_json: str = "",
legend_position: str = "right",
palette: list[int] | None = None,
background: str | None = None,
no_x_axis: bool = False,
no_y_axis: bool = False,
) -> Chart
Aliases: sp.hist, sp.histogram
Description
Distribution histogram with configurable bin count.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Chart title |
values | list[float] | required | Raw numerical data |
bins | int | 20 | Number of histogram bins |
show_counts | bool | False | Show count labels above each bar |
color_hex | int | 0 | Bar color as hex int |
width | int | 900 | Width in pixels |
height | int | 480 | Height in pixels |
Returns
Chart
Examples
Normal distribution
import seraplot as sp
import numpy as np
data = np.random.normal(0, 1, 5000).tolist()
chart = sp.build_histogram(
"Normal Distribution — N(0,1)",
values=data,
bins=40,
x_label="Value",
y_label="Count",
gridlines=True,
show_counts=False,
)const sp = require('seraplot');
function randn() {
const u = 1 - Math.random(), v = Math.random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
const data = Array.from({ length: 5000 }, () => randn());
const chart = sp.build_histogram("Normal Distribution — N(0,1)", {
values: data,
bins: 40,
x_label: "Value",
y_label: "Count",
gridlines: true,
show_counts: false,
});import * as sp from 'seraplot';
function randn(): number {
const u = 1 - Math.random(), v = Math.random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
const data: number[] = Array.from({ length: 5000 }, () => randn());
const chart = sp.build_histogram("Normal Distribution — N(0,1)", {
values: data,
bins: 40,
x_label: "Value",
y_label: "Count",
gridlines: true,
show_counts: false,
});▶ Live Preview
See also
- Histogram Overlay — compare two distributions
- KDE — smooth density estimate
- Violin — distribution by category
Signature
sp.build_histogram(
title: str,
values: list[float],
*,
color_hex: int = 0,
bins: int = 20,
show_counts: bool = False,
width: int = 900,
height: int = 480,
x_label: str = "",
y_label: str = "",
gridlines: bool = False,
sort_order: str = "none",
hover_json: str = "",
legend_position: str = "right",
palette: list[int] | None = None,
background: str | None = None,
no_x_axis: bool = False,
no_y_axis: bool = False,
) -> Chart
Aliases: sp.hist, sp.histogram
Description
Histogramme de distribution avec nombre de classes (bins) configurable.
Paramètres
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
title | str | requis | Titre du graphique |
values | list[float] | requis | Données numériques brutes |
bins | int | 20 | Nombre de classes |
show_counts | bool | False | Afficher les effectifs au-dessus de chaque barre |
color_hex | int | 0 | Couleur des barres (hex int) |
width | int | 900 | Largeur en pixels |
height | int | 480 | Hauteur en pixels |
Retourne
Chart
Exemples
Distribution normale
import seraplot as sp
import numpy as np
data = np.random.normal(0, 1, 5000).tolist()
chart = sp.build_histogram(
"Distribution normale — N(0,1)",
values=data,
bins=40,
x_label="Valeur",
y_label="Effectif",
gridlines=True,
show_counts=False,
)
Voir aussi
- Histogramme superposé — comparer deux distributions
- KDE — estimation de densité lisse
- Violon — distribution par catégorie