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:
- Sign in at mathworks.com with an institutional account and check whether a license is attached to it.
- Download the installer for Windows, macOS or Linux from MathWorks Downloads and choose a release. Heatmap charts need R2017a or later.
- 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
- Create or load a numeric matrix, for example
cdata = magic(5); - Call
h = heatmap(cdata);. A colorbar is shown by default. - Supply your own axis values with
heatmap(xvalues,yvalues,cdata), wherexvaluesandyvaluesname the columns and rows, for exampleh = heatmap({'A','B','C','D','E'},{'r1','r2','r3','r4','r5'},cdata); - 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
- Put the data in a table, for example one column for the x category, one for the y category and one numeric column.
- Call
h = heatmap(tbl,'Group','Condition');with the names of the two category variables. - 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'. - 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
- MathWorks: heatmap (read 2026-12-03)
- MathWorks: HeatmapChart properties (read 2026-12-03)
- MathWorks: imagesc (read 2026-12-03)
- MathWorks: MATLAB product page (read 2026-12-03)
- R documentation: heatmap (read 2026-12-03)
- seaborn documentation: seaborn.heatmap (read 2026-12-03)
- matplotlib documentation: imshow (read 2026-12-03)
- MathWorks: Trigonometry (read 2026-12-03)
- MathWorks: A Brief History of MATLAB (read 2026-12-03)
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.
| ColorMethod value | Default case | Restriction stated in the reference |
|---|---|---|
| count | Not a default | None stated |
| mean | Default when ColorVariable is given | None stated |
| median | Not a default | Not supported for tall arrays |
| sum | Not a default | None stated |
| max | Not a default | None stated |
| min | Not a default | None stated |
| none | Default for matrix data | Each x-y pair must appear once in the table; not supported for tall arrays |
Sources
- MathWorks: heatmap (accessed 2026-12-03)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







