From data to plot

How to make a scientific heat map

A scientific heat map shows a value over a two-dimensional plane as coloured cells. To make a heatmap from data, decide four things before reading any colour: the grid (cell shape and size), the statistic each cell holds, how empty and sparsely sampled cells are shown, and how values map to colour. Each of these changes the picture, so each belongs in the caption or methods.

Updated · 6 min read

On this page
  1. Gridded data, scattered points or a 2D histogram
  2. Heatmap binning: cell shape and resolution
  3. Choose the statistic per cell
  4. Empty and sparse cells
  5. 2D histograms and joint density
  6. Heatmap color scale and limits
  7. Contours and smoothing
  8. Making a heat map in Autoplot
  9. Frequently asked questions

Gridded data, scattered points or a 2D histogram

Start from what the rows represent. The same three columns can mean very different things.

InputWhat to doExample
A complete regular grid of z valuesDraw the cells directly; no binning neededSimulation output, image-like scans
Scattered observations with x, y and zBin into cells and aggregate z per cellSensor readings at irregular positions
Paired x and y onlyCount samples per cell: a 2D histogram or joint densityTwo measured quantities per event

Check that x, y and z describe the same observations in the same row order. Most tools pair columns by position, so a shifted or independently sorted column produces a confident-looking map of nothing.

Binning scattered observations is a summary, not interpolation. A cell's colour describes the observations that fell into it, not the value at its centre. A correlation matrix is drawn as a heatmap too, but its cells are relationships between variables, not values over a plane; see how to read a correlation matrix heatmap.

Heatmap binning: cell shape and resolution

Rectangular cells are easy to read against the axes and give a complete grid, so empty regions stay visible as gaps. Hexagonal cells have more uniform neighbour distances and reduce the visual artefacts of a square grid; many implementations draw only occupied hexagons, which hides where there are no data unless you show the extent another way.

Resolution is the main trade-off. Too coarse a grid merges distinct structure; too fine a grid leaves most cells with one or two samples and turns noise into speckle. There is no universally correct cell count:

  1. Start from a resolution where most occupied cells hold several samples.
  2. Rebuild the map at roughly half and double that resolution.
  3. Keep the features that survive all three; treat the rest as resolution-dependent.
  4. Report the cell count or cell size with the figure.

Choose the statistic per cell

When several observations fall into one cell, an aggregation reduces them to one value. This is a scientific choice, not a styling one.

StatisticAnswers
MeanWhat is the typical z here? Sensitive to outliers.
MedianWhat is the typical z, robust to a few extreme samples?
SumHow much of the quantity accumulated here?
Min / MaxWhat are the limits reached in this region?
Standard deviationHow variable is z within the cell?
Sample countHow much data supports each cell?

Pair the statistic you report with a sample-count map, at least while you work. A bright mean built from one observation carries much less weight than the same mean from a hundred.

Autoplot heat-map controls with x, y and z variables, 432 points, rectangular bins at an automatic 80 by 80 resolution, Mean as the Z value, a Viridis colour map, a colorbar and contours switched on
Variables, cell shape, resolution, statistic, colour map and contours sit on one panel. Every one of them changes what the reader sees, so every one belongs in the methods.

Empty and sparse cells

An empty cell means no observation landed there. Show it as empty, with a neutral background colour outside the colour map, rather than as the lowest colour on the scale, which reads as a measured minimum.

Sparse cells are harder. Common remedies, in order of preference:

  • Coarsen the grid until most occupied cells have enough samples.
  • Mask cells below a minimum count, so they appear empty rather than confident.
  • Show the count map beside the result, or as an inset, when coverage varies strongly across the plane.

Do not fill gaps by smoothing or interpolation unless the method is stated and the filled region is marked.

2D histograms and joint density

With only x and y, the cell value is the number of samples per cell. Three normalisations are common:

  • Count: samples in the cell. Depends on sample size and cell size.
  • Probability: count divided by the total number of samples. Cells sum to one.
  • Density: count divided by the total and by the cell area. Comparable across different cell sizes and shapes, and integrates to one.

Use density when maps with different resolutions or bin shapes must be compared. The same logic applies in one dimension; see histogram normalization.

Heatmap color scale and limits

Choose the colour map from what the values mean:

  • Sequential for magnitudes from low to high, such as concentration or count. Perceptually uniform maps like viridis keep equal steps in data looking like equal steps in colour.
  • Diverging when a centre value such as zero or a reference separates two directions. Put the centre at that value, not at the middle of the data range.
  • Cyclic for angles and phase, where the ends of the range meet.

Avoid rainbow and jet maps: their uneven lightness creates bands that are not in the data, and they fail for many colour-blind readers. Automatic limits suit exploration, but two maps with different automatic ranges give the same colour different meanings. Fix the limits when figures are compared, and consider a logarithmic normalisation when values span orders of magnitude. Keep the colorbar, with units, on every published map.

Autoplot rectangular heat map of binned z values over x and y axes with a Viridis colorbar labelled Z
The colorbar ties colour to values. The map is interpretable only with its grid, statistic, limits and empty-cell rule stated alongside.

Contours and smoothing

Contours should mark levels of the same field the colours show. Choose explicit levels when particular thresholds matter, and do not let lines suggest more precision than the cell size allows.

Smoothing softens cell boundaries in the rendering. It does not change the binned values, and a conclusion that depends on the smoothed look rather than the cells is not supported by the data. If three coordinates must stay explicit rather than being collapsed into colour, a 3D scatter plot may serve better.

In Autoplot

Making a heat map in Autoplot

In a Heat Map figure, Add Plot → Heat Map takes numeric X, Y and Z. Bin shape is Rectangular or Hexagonal; Auto resolution picks the cell count, or you set Cells X and Cells Y (or Hex Density). Z Value offers Mean, Median, Sum, Min, Max, Std Dev (population) and Sample Count. Rows are paired by position, rows with a non-finite value are skipped, and a manual X/Y range excludes rows outside it. Rectangular maps keep the full grid, with empty cells holding no value (NaN); hexagonal maps contain occupied cells only.

Manual Scale fixes the colour limits with Vmin and Vmax without changing the binned values. Contours take explicit or automatic levels, and Overlay Series draws raw X/Y points or a line over the map. Smoothing is applied in the rendering only. For x and y without z, Run Analysis → Joint Density Map reports Count, Probability or Density per cell, and the density and surface fits add Gaussian or custom 2D models. Binned cells, with their centres and values, can be exported back into the project as variables.

Heat maps are part of Plus. To see support, add a second map of the same data with Sample Count as the Z value. See the features page for the fits.

Frequently asked questions

Frequently asked questions
What is the difference between a heatmap and a 2D histogram?A 2D histogram is a heatmap whose cell value is the number of samples. A general heatmap can show any statistic of a third variable per cell, such as a mean or a maximum.
How many bins should a heatmap have?Enough that most occupied cells hold several samples, and few enough that real structure is not merged. Compare the map at half and double your chosen resolution and keep only features that survive.
Which colour map is best for a scientific heat map?A perceptually uniform sequential map such as viridis for magnitudes, and a diverging map centred on a meaningful value for signed data. Avoid rainbow maps.

Sources

Autoplot behaviour comes from the app's documentation for heat map figures and the heat map binning algorithm, checked on 9 October 2026, and from the features page. Matplotlib's guides to choosing colormaps and colormap normalisation explain perceptual uniformity and logarithmic scales. Crameri, Shephard and Heron, The misuse of colour in science communication, documents the distortions rainbow maps introduce.

Try it on your own data.

Heat maps, joint-density maps and their 2D fits are part of Autoplot Plus, which is free for the first 30 days. Build one map, export its binned cells and check that the pattern survives a change of grid.

Read a correlation matrix heatmap →
Download free for Mac Mac App Store

Apple silicon · macOS 15 or later · Free plan · Plus free for 30 days

Send to my Mac

Autoplot runs on a Mac. Send the link to yourself, or open it in the Mac App Store.