Heatmap
A two-dimensional matrix as colored cells. The Heatmap guide shows every feature on real data; this page is the contract: the function, the shape of its data, the keys style takes, and the constant each parameter accepts.
Function
datachart.charts.Heatmap
Heatmap(
data: HeatmapDataAttrs | list[HeatmapDataAttrs],
*,
title: str | None = None,
xlabel: str | None = None,
ylabel: str | None = None,
subtitle: str | list[str | None] | None = None,
emphasis: None = None,
emphasis_rule: EmphasisRuleAttrs | None = None,
figsize: FIG_SIZE | tuple[float, float] | None = None,
xmin: int | float | None = None,
xmax: int | float | None = None,
ymin: int | float | None = None,
ymax: int | float | None = None,
show_legend: bool | None = None,
legend: LegendSettingAttrs | None = None,
show_grid: SHOW_GRID | str | bool | None = None,
show_colorbars: bool | None = None,
show_heatmap_values: bool | None = None,
aspect_ratio: ASPECT_RATIO | str | None = None,
subplots: bool | None = None,
max_cols: int | None = None,
sharex: bool | None = None,
sharey: bool | None = None,
style: (
HeatmapStyleAttrs
| list[HeatmapStyleAttrs | None]
| None
) = None,
norm: str | list[str | None] | None = None,
vmin: float | list[float | None] | None = None,
vmax: float | list[float | None] | None = None,
valfmt: (
VALUE_FORMAT | str | list[str | None] | None
) = None,
xticks: (
list[int | float] | list[list[int | float]] | None
) = None,
xticklabels: list[str] | list[list[str]] | None = None,
xtickrotate: int | list[int | None] | None = None,
yticks: (
list[int | float] | list[list[int | float]] | None
) = None,
yticklabels: list[str] | list[list[str]] | None = None,
ytickrotate: int | list[int | None] | None = None,
xticks_format: (
VALUE_FORMAT | DATE_FORMAT | str | None
) = None,
yticks_format: (
VALUE_FORMAT | DATE_FORMAT | str | None
) = None,
colorbar: (
ColorbarSettingAttrs
| list[ColorbarSettingAttrs | None]
| None
) = None,
texts: (
TextSettingAttrs
| list[TextSettingAttrs]
| list[
TextSettingAttrs | list[TextSettingAttrs] | None
]
| None
) = None
) -> plt.Figure
Creates the heatmap.
A heatmap maps every cell of a 2-D matrix to a color, so structure in a grid of numbers (correlations, confusion matrices, feature-by-time tables) reads at a glance. Use it when both axes are categorical or gridded and the value is what matters; the color scale, colorbar, and cell value labels are all configurable.
Examples:
>>> from datachart.charts import Heatmap
>>> figure = Heatmap(
... data={
... "x": ["a", "b", "c"],
... "y": ["p", "q", "r"],
... "z": [
... [1, 2, 3],
... [4, 5, 6],
... [7, 8, 9],
... ],
... },
... title="Basic Heatmap",
... xlabel="X",
... ylabel="Y"
... )
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The labelled grid(s) for the heatmap(s): one
TYPE:
|
title
|
The title of the chart.
TYPE:
|
xlabel
|
The x-axis label.
TYPE:
|
ylabel
|
The y-axis label.
TYPE:
|
subtitle
|
The subtitle(s) for individual charts.
TYPE:
|
emphasis
|
Not supported: a heatmap has no series to mute or
highlight; set per-cell roles through the
TYPE:
|
emphasis_rule
|
A rule that highlights the cells matching it and mutes the rest:
TYPE:
|
figsize
|
The size of the figure.
TYPE:
|
xmin
|
The minimum x-axis value.
TYPE:
|
xmax
|
The maximum x-axis value.
TYPE:
|
ymin
|
The minimum y-axis value.
TYPE:
|
ymax
|
The maximum y-axis value.
TYPE:
|
show_legend
|
Whether to show the legend (not typical for heatmaps).
TYPE:
|
legend
|
The per-figure legend setting: title, location, column count
and alignment; each field falls back to the theme. See
TYPE:
|
show_grid
|
Which grid lines to show (e.g., "both", "x", "y");
TYPE:
|
show_colorbars
|
Whether to show the colorbar(s).
TYPE:
|
show_heatmap_values
|
Whether to show values on the heatmap cells.
TYPE:
|
aspect_ratio
|
The aspect ratio of the axes ("auto" or "equal"). See
TYPE:
|
subplots
|
Whether to create separate subplots for each heatmap.
TYPE:
|
max_cols
|
Maximum number of columns in subplots (when subplots=True).
TYPE:
|
sharex
|
Whether to share the x-axis in subplots.
TYPE:
|
sharey
|
Whether to share the y-axis in subplots.
TYPE:
|
style
|
Style configuration(s) for the heatmap(s).
TYPE:
|
norm
|
Value normalization method(s).
TYPE:
|
vmin
|
Minimum value(s) for normalization.
TYPE:
|
vmax
|
Maximum value(s) for normalization.
TYPE:
|
valfmt
|
Format string(s) for cell values, with the value named
TYPE:
|
xticks
|
Custom x-axis tick positions.
TYPE:
|
xticklabels
|
Custom x-axis tick labels.
TYPE:
|
xtickrotate
|
Rotation angle for x-axis tick labels.
TYPE:
|
yticks
|
Custom y-axis tick positions.
TYPE:
|
yticklabels
|
Custom y-axis tick labels.
TYPE:
|
ytickrotate
|
Rotation angle for y-axis tick labels.
TYPE:
|
xticks_format
|
The x-axis tick label format: a
TYPE:
|
yticks_format
|
The y-axis tick label format, as
TYPE:
|
colorbar
|
The colorbar setting(s): label, location, tick format, and tick
positions. See
TYPE:
|
texts
|
Text annotation(s) to draw.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
plt.Figure
|
The figure containing the heatmap. |
Data
Each record in data is a HeatmapDataAttrs; the emphasis parameter renames its keys.
datachart.typings.HeatmapDataAttrs
Bases: TypedDict
The data attributes for the heatmap chart.
| ATTRIBUTE | DESCRIPTION |
|---|---|
x |
The column labels, one per column of
TYPE:
|
y |
The row labels, one per row of
TYPE:
|
z |
The 2-D grid of cell values, one row per
TYPE:
|
emphasis |
The per-cell emphasis roles, aligned with
TYPE:
|
Style
style takes the keys of HeatmapStyleAttrs. The chart also reads the shared groups it draws: text annotations (TextStyleAttrs). Every key falls back to the theme, so the same keys set the default look through config.
datachart.typings.HeatmapStyleAttrs
Bases: TypedDict
The typing for the heatmap chart style.
| ATTRIBUTE | DESCRIPTION |
|---|---|
plot_heatmap_cmap |
The color map of the heatmap (palette name, single color, list of hex colors, or colormap).
TYPE:
|
plot_heatmap_alpha |
The alpha value of the heatmap.
TYPE:
|
plot_heatmap_font_size |
The font size of the heatmap.
TYPE:
|
plot_heatmap_font_color |
The font color of the heatmap.
TYPE:
|
plot_heatmap_font_style |
The font style of the heatmap.
TYPE:
|
plot_heatmap_font_weight |
The font weight of the heatmap.
TYPE:
|
plot_heatmap_frame_color |
The color of the frame always drawn around heatmap axes.
TYPE:
|
plot_heatmap_edge_width |
The width of the borders drawn between the cells (0 draws none).
TYPE:
|
plot_heatmap_edge_color |
The color of the borders drawn between the cells.
TYPE:
|
Constants
The parameters that accept a constant, with the class in datachart.constants that lists its values.
| Parameter | Constant |
|---|---|
figsize |
FIG_SIZE |
legend={"location": ..., "alignment": ...} |
LEGEND_LOCATION, LEGEND_ALIGN |
show_grid |
SHOW_GRID |
aspect_ratio |
ASPECT_RATIO |
norm |
NORMALIZE |
valfmt |
VALUE_FORMAT |
xticks_format |
VALUE_FORMAT, DATE_FORMAT |
yticks_format |
VALUE_FORMAT, DATE_FORMAT |
colorbar={"location": ..., "format": ..., "orientation": ...} |
COLORBAR_LOCATION, VALUE_FORMAT, ORIENTATION |