Matrix pattern exploration
Inspect numeric tables where magnitude and patterns matter more than exact values.
Seaborn · Function
seaborn.heatmap displays a rectangular two-dimensional dataset as a color-encoded matrix. It can add annotations, cell borders, labels, masking, and a colorbar.
heatmap renders a rectangular two-dimensional dataset as a matrix whose cell colors encode values. It operates on the active Matplotlib Axes unless you provide ax, and it normally reserves part of that Axes for a colorbar.
seaborn.heatmap(data, *, vmin=None, vmax=None, cmap=None, center=None, robust=False, annot=None, fmt='.2g', annot_kws=None, linewidths=0, linecolor='white', cbar=True, cbar_kws=None, cbar_ax=None, square=False, xticklabels='auto', yticklabels='auto', mask=None, ax=None, **kwargs)| Name | Type | Description |
|---|---|---|
data | rectangular dataset | Rectangular two-dimensional dataset that can be converted to an array; DataFrame labels are used for rows and columns. |
vmin, vmax | float, optional | Lower and upper values anchoring the colormap; inferred when omitted. |
cmap | matplotlib colormap name or object, optional | Colormap name or Matplotlib colormap object. |
center | float, optional | Value at which to center the colormap. |
robust | bool, optional | If true, compute color limits using robust quantiles rather than extremes. |
annot | bool or rectangular dataset, optional | Whether to annotate cells, or a separate rectangular annotation dataset. |
fmt | str, optional | Formatting string for annotation text. |
annot_kws | dict, optional | Keyword arguments passed to annotation text. |
linewidths, linecolor | float, str, optional | Width and color of lines separating cells. |
cbar, cbar_kws, cbar_ax | bool, dict, matplotlib Axes, optional | Whether to draw a colorbar and options controlling it. |
square | bool, optional | Whether to force square cells. |
xticklabels, yticklabels | bool, int, list, or auto, optional | Controls column and row tick labels. |
matplotlib Axes. The function draws the heatmap on the supplied or active Axes.
import seaborn as sns
import matplotlib.pyplot as plt
values = [[1, 2, 3], [4, 5, 6]]
sns.heatmap(values, annot=True, fmt="d", cmap="crest")
plt.show()This draws a numeric matrix with cell values displayed as annotations and uses the named crest colormap.
Inspect numeric tables where magnitude and patterns matter more than exact values.
Display correlations with a diverging palette, centered scale, and optional mask.
Show values directly inside cells with controlled formatting.
The function accepts a rectangular two-dimensional dataset and maps its values to colors. A DataFrame also contributes its index and column labels to the plot.
Follow-up: How would you show values in each cell? Pass annot=True, then use fmt to control their formatting.
annot=True writes the cell values as text, while fmt controls the formatting string used for those annotations. You can also pass a separate rectangular dataset through annot.
Follow-up: How can annotation text be styled? Supply a dictionary through annot_kws.
heatmap is an Axes-level function, so it draws into the current Axes when ax is omitted. It creates a colorbar by default unless cbar is false or a separate cbar_ax is supplied.
Follow-up: How can the color scale be bounded? Set vmin and vmax to anchor the colormap limits.
clustermapset_themeload_datasetcubehelix_palettediverging_palette