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

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

ParameterTypeDefaultDescription
titlestrrequiredChart title
valueslist[float]requiredFirst distribution data
overlay_valueslist[float]requiredSecond distribution data
binsint20Number of bins
series_nameslist[str] | NoneNoneNames for legend ["Series A", "Series B"]
color_hexint0Color for first series
overlay_color_hexint0Color 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ètreTypeDéfautDescription
titlestrrequisTitre du graphique
valueslist[float]requisDonnées de la première distribution
overlay_valueslist[float]requisDonnées de la deuxième distribution
binsint20Nombre de classes
series_nameslist[str] | NoneNoneNoms pour la légende ["Série A", "Série B"]
color_hexint0Couleur de la première série
overlay_color_hexint0Couleur 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,
)

Voir aussi