Heatmap

On this page 7

A heatmap is a data visualization that represents values in a two-dimensional grid of cells, with each cell colored according to its magnitude. In visualization, it is used to show how a measure varies across two categorical or binned dimensions at once, such as hour by weekday, product by region or variable by variable, so that patterns, clusters and outliers become visible without reading individual numbers.

The effectiveness of a heatmap depends less on the grid than on the color scale: how values are mapped to hues and lightness, where the scale starts and ends, and whether the colors remain distinguishable for every reader.

How a heatmap encodes data

A heatmap encodes data by placing one dimension on the rows, another on the columns and mapping the value of each cell to a color. The reader compares cells by color rather than by position or length, which makes heatmaps excellent for spotting broad structure and weaker for reading exact values.

Building one involves three decisions: aggregating raw data into cells (for example, counting events per hour and weekday), choosing a color scale and deciding on row and column order. Ordering matters because similar rows placed next to each other form visible blocks, while an arbitrary order scatters the same pattern into noise.

The table below lists the components that every heatmap specification should define.

ComponentRoleTypical choices
Row dimensionGroups shown verticallyCategories, entities, time bins
Column dimensionGroups shown horizontallyCategories, periods, variables
Cell valueMeasure being comparedCount, mean, rate, correlation
Color scaleMaps values to colorsSequential, diverging, categorical
LegendExplains the mappingContinuous bar or labeled steps
OrderingArranges rows and columnsNatural order, sorted, clustered
Components of a heatmap

Types of heatmaps and color scales

Heatmaps vary by what the grid represents. The term covers several related forms, and choosing the right color scale type for each is the most important design decision.

TypeWhat the grid showsTypical use
Matrix heatmapTwo categorical dimensionsSales by product and region
Calendar heatmapDays arranged in weeksDaily activity over a year
Correlation matrixVariables against variablesExploring relationships before modeling
Clustered heatmapRows and columns reordered by similarityGene expression, customer segments
Density heatmapBinned two-dimensional numeric dataDense scatter data with overplotting
Common heatmap types

A sequential scale runs from light to dark in one hue and suits values that go from low to high, such as counts. A diverging scale uses two hues around a meaningful midpoint and suits values with a natural center, such as correlation coefficients from -1 to +1 or change against a target. Using a sequential scale for diverging data hides the midpoint, and using a diverging scale without a real midpoint invents one.

Perceptually uniform color maps, in which equal steps in value look like equal steps in color, avoid false boundaries. The traditional rainbow color map fails this test: bright yellow and cyan bands draw the eye to arbitrary values and make some ranges look flatter than they are.

Heatmaps compared with other chart types

A heatmap trades precision for overview. Position along a common axis, as in a bar chart or line chart, is read far more accurately than color, so a heatmap is the better choice only when the number of cells is too large for those charts to remain legible.

ChartBest atWeakness compared with a heatmap
HeatmapPatterns across two dimensionsImprecise reading of single values
Bar chartExact comparison of a few categoriesBecomes cluttered beyond one dimension
Line chartTrends over continuous timeMany overlapping lines are hard to read
Scatter plotRelationship between two numeric variablesOverplotting with very many points
HistogramDistribution of one variableShows only one dimension
Heatmap and neighboring charts

Within a dashboard, heatmaps work well as a navigation layer: a reader spots an unusual cell, then drills into a line chart or table for the exact figures. Adding the numeric value inside each cell helps when the grid is small, roughly up to a few hundred cells, but makes larger grids unreadable.

Designing a readable heatmap

A readable heatmap results from a few deliberate choices about scale, order and labeling. The decision table below summarizes the most common situations.

SituationRecommended choiceReason
Values from zero upwardSequential single-hue scaleDarker reads naturally as more
Values around a target or zeroDiverging scale centered on itShows direction and size of deviation
A few extreme outliersCapped or quantile-based scalePrevents outliers washing out the rest
Unknown structure in many rowsHierarchical clustering orderGroups similar rows into blocks
Audience includes color vision deficiencyLightness-based or tested paletteAvoids red-green confusion
Design choices by situation

Labels should include the unit and aggregation in the legend (for example, “median minutes per order”), and empty cells should be visually distinct from zero. A missing value shown in the lightest color will be read as a real low value, which is one of the most damaging and least noticed errors.

Limitations and common mistakes

The central limitation of a heatmap is that humans judge color poorly in absolute terms. The same shade looks different depending on its neighbors, so two cells far apart on the grid are hard to compare reliably.

  • Unequal group sizes: raw counts make large groups look hot simply because they are large, so rates or normalized values are often more honest.
  • Arbitrary binning of continuous data, where changing the bin width can create or erase apparent patterns.
  • Misleading scale limits, such as a scale that starts above zero and exaggerates small differences.
  • Overinterpreting clustering, since clustered order will always produce some blocks, even in random data.
  • Unrelated heatmaps sharing different scales side by side, which invites false comparison.

A non-technical view

A heatmap is a table where the numbers are replaced by colors. Instead of reading every figure, you look at the whole grid and see at once where things are high and where they are low.

Think of a weather map that shades hot regions red and cool regions blue. You do not need the exact temperature of each town to see that the south is warmer. A heatmap does the same for any kind of data. The main thing to remember is that it is good for spotting patterns quickly, while the exact numbers still belong in a table or chart.

A concrete example

A city bike-sharing operator wants to plan when to move bikes between stations. Analysts count rentals for each hour of the day across the seven weekdays over six months and display the result as a 24-by-7 heatmap with a sequential blue scale.

The grid shows two dark bands on weekdays, around 8:00 and between 17:00 and 18:00, and a broad lighter area on weekend afternoons. A diverging version comparing each station with the citywide average reveals that several stations near the main railway station run well above average in the morning peak. The operator schedules redistribution trucks before 7:30 on weekdays, and the share of trips that could not start because a station was empty drops noticeably in the following month.