Histogram Overlay
Signature
sp.build_histogram_overlay(
title: str,
values: list[float],
overlay_values: list[float],
*,
color_hex: int = 0,
overlay_color_hex: int = 0,
bins: int = 20,
series_names: list[str] | None = None,
width: int = 900,
height: int = 480,
x_label: str = "",
y_label: str = "",
gridlines: bool = False,
palette: list[int] | None = None,
background: str | None = None,
no_x_axis: bool = False,
no_y_axis: bool = False,
) -> Chart
Aliases: sp.histogram_overlay
Description
Overlaid histogram comparing two distributions side-by-side with transparency.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Chart title |
values | list[float] | required | First distribution data |
overlay_values | list[float] | required | Second distribution data |
bins | int | 20 | Number of bins |
series_names | list[str] | None | None | Names for legend ["Series A", "Series B"] |
color_hex | int | 0 | Color for first series |
overlay_color_hex | int | 0 | Color for second series |
Returns
Chart
Examples
import seraplot as sp
import numpy as np
rng = np.random.default_rng(42)
control = rng.normal(5.0, 1.0, 1000).tolist()
treatment = rng.normal(5.8, 1.2, 1000).tolist()
chart = sp.build_histogram_overlay(
"Control vs Treatment",
values=control,
overlay_values=treatment,
bins=30,
series_names=["Control", "Treatment"],
x_label="Measurement",
y_label="Frequency",
gridlines=True,
)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 control = Array.from({ length: 1000 }, () => 5.0 + 1.0 * randn());
const treatment = Array.from({ length: 1000 }, () => 5.8 + 1.2 * randn());
const chart = sp.build_histogram_overlay("Control vs Treatment", control, {
overlay_values: treatment,
bins: 30,
series_names: ["Control", "Treatment"],
x_label: "Measurement",
y_label: "Frequency",
gridlines: true,
});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 control: number[] = Array.from({ length: 1000 }, () => 5.0 + 1.0 * randn());
const treatment: number[] = Array.from({ length: 1000 }, () => 5.8 + 1.2 * randn());
const chart = sp.build_histogram_overlay("Control vs Treatment", control, {
overlay_values: treatment,
bins: 30,
series_names: ["Control", "Treatment"],
x_label: "Measurement",
y_label: "Frequency",
gridlines: true,
});▶ Live Preview
See also
Signature
sp.build_histogram_overlay(
title: str,
values: list[float],
overlay_values: list[float],
*,
color_hex: int = 0,
overlay_color_hex: int = 0,
bins: int = 20,
series_names: list[str] | None = None,
width: int = 900,
height: int = 480,
x_label: str = "",
y_label: str = "",
gridlines: bool = False,
palette: list[int] | None = None,
background: str | None = None,
no_x_axis: bool = False,
no_y_axis: bool = False,
) -> Chart
Aliases: sp.histogram_overlay
Description
Histogramme superposé pour comparer deux distributions avec transparence.
Paramètres
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
title | str | requis | Titre du graphique |
values | list[float] | requis | Données de la première distribution |
overlay_values | list[float] | requis | Données de la deuxième distribution |
bins | int | 20 | Nombre de classes |
series_names | list[str] | None | None | Noms pour la légende ["Série A", "Série B"] |
color_hex | int | 0 | Couleur de la première série |
overlay_color_hex | int | 0 | Couleur de la deuxième série |
Retourne
Chart
Exemples
import seraplot as sp
import numpy as np
rng = np.random.default_rng(42)
controle = rng.normal(5.0, 1.0, 1000).tolist()
traitement = rng.normal(5.8, 1.2, 1000).tolist()
chart = sp.build_histogram_overlay(
"Contrôle vs Traitement",
values=controle,
overlay_values=traitement,
bins=30,
series_names=["Contrôle", "Traitement"],
x_label="Mesure",
y_label="Fréquence",
gridlines=True,
)