Heatmap
Signature
sp.build_heatmap(
title: str,
labels: list[str],
flat_matrix: list[float],
*,
show_values: bool = True,
color_low: int = 0,
color_mid: int = 0,
color_high: int = 0,
col_labels: 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.heatmap
Description
Color-coded matrix heatmap. Values are automatically normalized for color mapping.
flat_matrix must contain n_rows × n_cols values in row-major order.
labels = row labels. col_labels = column labels (if different from rows).
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | required | Chart title |
labels | list[str] | required | Row labels |
flat_matrix | list[float] | required | Matrix values, row-major |
show_values | bool | True | Overlay numeric values in cells |
color_low | int | auto | Low value color (hex int) |
color_mid | int | auto | Mid value color |
color_high | int | auto | High value color |
col_labels | list[str] | None | None | Column labels (defaults to labels) |
Returns
Chart
Examples
Correlation matrix
import seraplot as sp
import numpy as np
features = ["Age", "Income", "Score", "Visits"]
n = len(features)
matrix = np.corrcoef(np.random.randn(4, 100)).flatten().tolist()
chart = sp.build_heatmap(
"Feature Correlation Matrix",
labels=features,
flat_matrix=matrix,
color_low=0x3b82f6,
color_mid=0xffffff,
color_high=0xef4444,
show_values=True,
)const sp = require('seraplot');
const features = ["Age", "Income", "Score", "Visits"];
// Pre-computed 4×4 correlation matrix (row-major)
const matrix = [
1.00, 0.72, -0.15, 0.43,
0.72, 1.00, 0.08, 0.61,
-0.15, 0.08, 1.00, -0.27,
0.43, 0.61, -0.27, 1.00,
];
const chart = sp.build_heatmap("Feature Correlation Matrix", features, {
flat_matrix: matrix,
color_low: 0x3b82f6,
color_mid: 0xffffff,
color_high: 0xef4444,
show_values: true,
});import * as sp from 'seraplot';
const features: string[] = ["Age", "Income", "Score", "Visits"];
// Pre-computed 4×4 correlation matrix (row-major)
const matrix: number[] = [
1.00, 0.72, -0.15, 0.43,
0.72, 1.00, 0.08, 0.61,
-0.15, 0.08, 1.00, -0.27,
0.43, 0.61, -0.27, 1.00,
];
const chart = sp.build_heatmap("Feature Correlation Matrix", features, {
flat_matrix: matrix,
color_low: 0x3b82f6,
color_mid: 0xffffff,
color_high: 0xef4444,
show_values: true,
});▶ Live Preview
See also
Signature
sp.build_heatmap(
title: str,
labels: list[str],
flat_matrix: list[float],
*,
show_values: bool = True,
color_low: int = 0,
color_mid: int = 0,
color_high: int = 0,
col_labels: 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.heatmap
Description
Matrice colorée (heatmap). Les valeurs sont normalisées automatiquement pour le mappage de couleurs.
flat_matrix doit contenir n_lignes × n_colonnes valeurs en ordre ligne-major. labels = étiquettes de lignes. col_labels = étiquettes de colonnes.
Paramètres
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
title | str | requis | Titre du graphique |
labels | list[str] | requis | Étiquettes des lignes |
flat_matrix | list[float] | requis | Valeurs de la matrice, en ligne-major |
show_values | bool | True | Afficher les valeurs numériques dans les cellules |
color_low | int | auto | Couleur pour les valeurs basses (hex int) |
color_mid | int | auto | Couleur pour les valeurs médianes |
color_high | int | auto | Couleur pour les valeurs hautes |
col_labels | list[str] | None | None | Étiquettes de colonnes (par défaut = labels) |
Retourne
Chart
Exemples
Matrice de corrélation
import seraplot as sp
import numpy as np
features = ["Age", "Revenu", "Score", "Visites"]
matrice = np.corrcoef(np.random.randn(4, 100)).flatten().tolist()
chart = sp.build_heatmap(
"Matrice de corrélation des variables",
labels=features,
flat_matrix=matrice,
color_low=0x3b82f6,
color_mid=0xffffff,
color_high=0xef4444,
show_values=True,
)