heatmap

Heatmap chart that shows a matrix, or two table variables, as colored cells.

Category: Graphics > 2-D and 3-D Plots

Syntax

heatmap(cdata)

Draws one cell per element of the matrix cdata, colored by its value.

heatmap(xvalues, yvalues, cdata)

Labels the columns with xvalues and the rows with yvalues.

heatmap(tbl, xvar, yvar)

Counts the rows of the table tbl for each pair of values of the variables xvar and yvar.

h = heatmap(___)

Also returns the chart object, whose properties (Title, Colormap, ColorData) can be changed.

Description

A heatmap is a good way to read a correlation matrix, a confusion matrix or any grid of numbers, because the color gives a quick overview while the labels keep the cells identifiable. The color scale is set by the smallest and largest values and follows the current colormap.

Unlike imagesc, heatmap is a chart: it has category labels, not numeric axes.

Input arguments

cdata
Numeric matrix, one value per cell.
xvalues, yvalues
Labels for the columns and rows: cell array of character vectors, string array or numeric vector.
tbl, xvar, yvar
Table and the names of two of its variables.

Output arguments

h
HeatmapChart object.

Example

Labelled matrix

cdata = [10 2 0; 3 12 1; 0 4 9];
h = heatmap({'A','B','C'}, {'A','B','C'}, cdata);
h.Title = 'Confusion matrix';

In the app, the chart is drawn below the code.

See also

imagesc pcolor bubblechart histogram2 table