Skip to main content
v2026.11,986 entries · CC-BY 4.0

Heatmap in MATLAB: heatmap() Syntax, Colors and Labels

MATLAB heatmap() syntax for matrices and tables, ColorMethod aggregation, cell labels and colors, and how it differs from imagesc.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

A heatmap in MATLAB is made with the heatmap function, which draws a matrix or a table as a grid of colored cells. The shortest working call is h = heatmap(cdata), where cdata is a numeric matrix. MathWorks lists the function as introduced in R2017a, so any later release has it.

The MathWorks documentation describes five call forms, covered below, and a set of chart properties that control color, labels and missing values. This page gathers them in one reference, adds a comparison with imagesc, and lists the failures that most often appear when a table or matrix does not plot as expected.

What heatmap in MATLAB is used for in research

What is a heat map used for?

A heat map shows the values in a matrix or a two-way summary as colors, so patterns across rows and columns can be seen at a glance. Typical research uses are a correlation matrix between measured variables, counts or averages for each combination of two categories, and a grid of results across two experimental settings. The reader compares color rather than reading each number, which is why the cell values are often shown as well.

MATLAB offers two routes. heatmap creates a heatmap chart object that can summarise a table for you. imagesc displays a matrix as a scaled image. The comparison table in the section on reading the output sets them side by side. For the general question of which chart suits which data, see data visualization examples.

What is the MATLAB full form?

MATLAB stands for MATrix LABoratory. MathWorks co-founder Cleve Moler describes the name as an acronym for Matrix Laboratory in the company’s article A Brief History of MATLAB (read 2026-12-03). MathWorks itself describes the product as a programming and numeric computation environment for algorithm development, data analysis and visualization.

How to install or access MATLAB

Use the official MathWorks route only. According to the MATLAB product page (read 2026-12-03), you can already have access through your university or company account, and signing in with that account may provide it. Otherwise the page lists these routes:

  1. Sign in at mathworks.com with an institutional account and check whether a license is attached to it.
  2. Download the installer for Windows, macOS or Linux from MathWorks Downloads and choose a release. Heatmap charts need R2017a or later.
  3. Try the product through the free trial or MATLAB Online, both reached from the MATLAB product page, if no license is available yet.

Pricing and license terms change and are set by MathWorks; check the product page rather than a third-party summary. See MathWorks: MATLAB.

How to make a heatmap in MATLAB step by step

There are two kinds of input: a numeric matrix, and a table with one column for each axis. The call forms listed in the heatmap reference are heatmap(tbl,xvar,yvar), heatmap(tbl,xvar,yvar,'ColorVariable',cvar), heatmap(cdata), heatmap(xvalues,yvalues,cdata) and heatmap(___,Name=Value). Calling h = heatmap(___) returns the chart object so you can set properties afterwards.

Heatmap from a matrix

  1. Create or load a numeric matrix, for example cdata = magic(5);
  2. Call h = heatmap(cdata);. A colorbar is shown by default.
  3. Supply your own axis values with heatmap(xvalues,yvalues,cdata), where xvalues and yvalues name the columns and rows, for example h = heatmap({'A','B','C','D','E'},{'r1','r2','r3','r4','r5'},cdata);
  4. Set a title with h.Title = 'Correlation between variables';. The documentation says Title accepts a character vector, cell array, string array or categorical array, and interprets TeX markup by default.

Heatmap from a table

  1. Put the data in a table, for example one column for the x category, one for the y category and one numeric column.
  2. Call h = heatmap(tbl,'Group','Condition'); with the names of the two category variables.
  3. To color by a numeric column, add it: h = heatmap(tbl,'Group','Condition','ColorVariable','Score');. The ColorVariable must be numeric or logical, and the default aggregation is then 'mean'.
  4. Change the aggregation with the ColorMethod name-value argument, for example 'ColorMethod','median'. The allowed values are in the data table below.

The data table below lists each ColorMethod value and its restriction, taken from the reference page.

How to read the heatmap output

Each cell is one x-y pair and its color encodes the value. The default colormap is 256 samples of sky, and a colorbar is displayed, because ColorbarVisible defaults to ‘on’. Cell labels use the format ‘%0.4g’ by default, so a value such as 0.123456 shows as 0.1235.

Key chart properties and their defaults

Property Default What it controls
CellLabelFormat ‘%0.4g’ Number format of the text in each cell
CellLabelColor ‘auto’ Color of the cell text
ColorScaling ‘scaled’ How data map to the color limits; scaled normalizes each column in ColorData to values 0 through 1
ColorLimits Reflects the data range after ColorScaling Lower and upper bounds of the color scale
ColorbarVisible ‘on’ Whether the colorbar is shown
GridVisible ‘on’ Whether lines separate the cells
MissingDataLabel ‘NaN’ Text shown in cells with missing data
MissingDataColor Set by you (RGB, hex or name) Fill color of missing-data cells
XDisplayLabels The XDisplayData values, which default to the XData values Labels shown on the axes

Source: HeatmapChart properties, read 2026-12-03. For example, h.Colormap = parula; changes the palette and h.CellLabelFormat = '%0.2f'; shows two decimals. The guide to MATLAB colormap colors covers palette choice.

heatmap versus imagesc

Question heatmap imagesc
Input forms in the reference A table with variable names, or a matrix, with optional x and y values A matrix C, with optional x and y
Aggregation of table rows ColorMethod: count, mean, median, sum, max, min or none None described; it displays C as given
Cell text CellLabelFormat and CellLabelColor properties No cell-label property on the reference page
Color mapping ColorScaling and ColorLimits properties Smallest value maps to the first colormap color and largest to the last; default CLim is the min and max of C; set clims = [cmin cmax] to override, with values outside the range clipped

Sources: heatmap and imagesc, read 2026-12-03.

Choosing the aggregation for table input

When the table has several rows for the same x-y pair, the ColorMethod decides how those rows become one cell color. The method is part of what the figure claims, so choose it on purpose rather than leaving the default.

  • mean or median suits a measured outcome such as a score; the median is the choice when a few extreme rows would pull a mean. Both need a numeric or logical ColorVariable.
  • sum suits quantities that add up, such as totals per pair.
  • max or min suits questions about the extreme value in each pair.
  • count suits showing how many rows fall in each pair.
  • none suits data that already has one row per pair, which is what a matrix is.

The MathWorks page specifies only the default and the restrictions listed in the data table; the guidance above is an editorial reading of what each statistic measures.

Documenting a heatmap in a paper or report

A heatmap figure is easier to reproduce when the caption or methods text states four things: the function and MATLAB release, the ColorMethod or the fact that the input was a matrix, the color limits, and how missing cells are shown. The release matters because the function was introduced in R2017a and the reference page records later changes, such as TeX markup in heatmap text from R2019a. Stating the color limits matters because, by default, ColorLimits follows the data range after ColorScaling, so two figures built from different datasets will not share a color scale unless you set it.

For wider guidance on choosing and describing figures, see data visualisation types in research software.

Troubleshooting heatmap in MATLAB

Error with ColorMethod ‘none’

The documentation states that ‘none’ requires each x-y pair to appear only once in the table. If a pair repeats, choose an aggregation such as ‘mean’ or ‘sum’, or remove the duplicates first. ‘none’ is the default for matrix input, which has one value per cell.

‘median’ or ‘none’ fails on tall arrays

For tall arrays the reference page excludes ‘none’ and ‘median’. Use ‘mean’, ‘sum’, ‘count’, ‘max’ or ‘min’ instead.

Empty or NaN cells

Cells with missing data show the MissingDataLabel, which is ‘NaN’ by default, in the MissingDataColor. Set h.MissingDataLabel = ''; to hide the text or h.MissingDataColor = [0.8 0.8 0.8]; to choose the fill.

Colors look uneven across columns

With the default ColorScaling of ‘scaled’, the documentation says each column of ColorData is normalized to 0 through 1, so a color means a value relative to its own column. ColorLimits, whose default reflects the data range after ColorScaling, is the property that holds the lower and upper bounds of the scale.

Numbers in cells are cut off or too long

Change CellLabelFormat from the default ‘%0.4g’, for example to ‘%0.1f’.

Free alternatives to MATLAB heatmaps

If you do not have a MATLAB license, the same figure can be made in free, open-source tools. The table below states what each tool’s own documentation says its heatmap function does, and CASRAI has a separate guide for each.

Tool Function What its documentation says CASRAI guide
R (stats package) heatmap() Draws a false-color image of a numeric matrix with dendrograms on the left and top; rows and columns are reordered by default, and setting Rowv = NA or Colv = NA suppresses the dendrogram and reordering Heatmap in R
matplotlib (Python) imshow() Displays data as an image on a 2D regular raster; 2D scalar data is rendered as a pseudocolor image Heatmap in matplotlib
seaborn (Python) heatmap() Plots rectangular data as a color-encoded matrix; annot=True writes each cell value, cmap sets the colormap, vmin and vmax anchor the color scale Heatmap in seaborn

One difference matters when porting a figure. R’s heatmap() reorders rows and columns by clustering unless told not to, whereas MATLAB’s heatmap keeps the order of your data. MATLAB’s imagesc and matplotlib’s imshow are the closest counterparts, as both display a matrix as a color image, and both let you set the data values at the ends of the color scale (clims in MATLAB, vmin and vmax in matplotlib).

Frequently asked questions

What is a heat map used for?

It displays the values of a matrix or a two-way summary as colors, so patterns across rows and columns are visible without reading every number.

What is the MATLAB full form?

MATrix LABoratory, according to MathWorks co-founder Cleve Moler’s history of the software.

Is MATLAB in rad or deg?

Trigonometric functions such as sin take radians, and the degree versions have a d suffix, such as sind. The MathWorks trigonometry reference lists sin as the sine of an argument in radians and sind as the sine of an argument in degrees. So sin(30) treats 30 as radians; use sind(30) for degrees.

How do I create a heatmap in Tableau?

Tableau is a different product from MATLAB and is not covered here; use Tableau’s own documentation. In MATLAB, use heatmap as described above.

Sources

Data: heatmap ColorMethod values for table input in MATLAB

Compiled from the MathWorks heatmap reference page: each ColorMethod value, when it is the default, and its stated restrictions for tables and tall arrays.

heatmap ColorMethod values for table input in MATLAB
ColorMethod valueDefault caseRestriction stated in the reference
countNot a defaultNone stated
meanDefault when ColorVariable is givenNone stated
medianNot a defaultNot supported for tall arrays
sumNot a defaultNone stated
maxNot a defaultNone stated
minNot a defaultNone stated
noneDefault for matrix dataEach x-y pair must appear once in the table; not supported for tall arrays

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Heatmap in MATLAB: heatmap() Syntax, Colors and Labels

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →