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

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

ParameterTypeDefaultDescription
titlestrrequiredChart title
valueslist[float]requiredRaw numerical data
binsint20Number of histogram bins
show_countsboolFalseShow count labels above each bar
color_hexint0Bar color as hex int
widthint900Width in pixels
heightint480Height 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

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ètreTypeDéfautDescription
titlestrrequisTitre du graphique
valueslist[float]requisDonnées numériques brutes
binsint20Nombre de classes
show_countsboolFalseAfficher les effectifs au-dessus de chaque barre
color_hexint0Couleur des barres (hex int)
widthint900Largeur en pixels
heightint480Hauteur 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