Data AnalyticsData Visualizationbeginner
Updated:

Heatmaps in Data Analysis

4 min read

Heatmaps turn a grid of numbers into a field of color, making patterns across two dimensions pop. Learn correlation matrices, cross-tabs, and honest color scales.

TL;DR – Quick Answer

A heatmap encodes a numeric value as color across a two-dimensional grid, so patterns across two categorical dimensions become visible at once. Common uses are correlation matrices and cross-tabs like sales by month and region. The color scale choice is critical: use a sequential scale for ordered magnitudes and a diverging scale for values centered on a meaningful midpoint like zero.

On This Page

Some questions have two dimensions at once: how do sales vary by both month and region, how does website traffic differ by day of week and hour, how do a dozen variables correlate with each other. Reading these from a table of numbers is slow and error-prone. A heatmap solves it by mapping each value to a color and laying the values out in a grid, so patterns — hot rows, cold columns, bright diagonals — jump out before you read a single number.

Heatmaps are a favorite for exploratory analysis because they compress a large table into a picture. The catch is that color is a weaker channel than position, so the color scale must be chosen with care, or the heatmap will mislead.

How a heatmap works

A heatmap is a grid where rows and columns are two categorical dimensions and each cell's color encodes a numeric value. The reader scans for regions of intense color, which mark where the value is high or low. Because the eye takes in the whole grid at once, a heatmap surfaces clusters and gradients that a table buries.

The most common analytical heatmap is the correlation matrix: every variable against every other, each cell colored by how strongly the pair correlates.

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

# Illustrative sample: five metrics across a handful of stores
df = pd.DataFrame({
    "footfall":   [120, 200, 150, 300, 250, 180],
    "sales":      [22, 40, 28, 60, 48, 35],
    "staff":      [3, 5, 4, 7, 6, 4],
    "returns":    [2, 5, 3, 8, 6, 4],
    "rating":     [4.6, 4.2, 4.5, 4.0, 4.1, 4.4],
})

corr = df.corr()

fig, ax = plt.subplots(figsize=(6, 5))
sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm",
            vmin=-1, vmax=1, center=0, square=True, ax=ax)
ax.set_title("Correlation between store metrics",
             loc="left", fontweight="bold")
plt.tight_layout()
plt.show()
What this renders: a 5x5 grid where each cell shows the correlation
between two metrics, colored on a blue-white-red diverging scale.
Strong positive pairs (footfall and sales, sales and staff) appear
deep red near 1.0; rating shows cool blue negative correlations with
sales and returns. The diagonal is deep red at 1.00. The number in
each cell gives the exact value, so pattern and precision are both
available.

The center=0 with a diverging coolwarm scale is deliberate: correlation runs from -1 to +1 around a meaningful zero, so a diverging palette is the honest choice.

Choosing the color scale

Color scale choice is where heatmaps succeed or fail, and it follows the same logic covered in color in data visualization:

  • Sequential (light to dark of one hue) for values that run low to high with no natural midpoint — sales, counts, traffic. Darker means more.
  • Diverging (two hues meeting at a neutral center) for values centered on a meaningful midpoint — correlations, percent change from baseline, profit versus loss.
  • Avoid rainbow. A rainbow scale has no perceptual order, so readers cannot tell which color means "more." It also fails for colorblind viewers.

A cross-tab heatmap

Beyond correlation, heatmaps shine for cross-tabulated business data — a value summarized across two dimensions.

Sales heatmap: month (rows) x region (cols), darker = higher

        North  South  East   West
Jan     [dim]  [dark] [mid]  [dim]
Feb     [dim]  [dark] [mid]  [mid]
Mar     [mid]  [dark] [dark] [mid]
Apr     [mid]  [dark] [dark] [dark]
Reading: South is consistently strong; activity spreads to East and
West as the year progresses, visible as columns warming over the rows.

Practical usage

Analysts use correlation heatmaps early in a project to spot which variables move together, which flags redundant features and promising relationships to explore with scatter plots. Cross-tab heatmaps appear in reporting for time-by-category patterns — the classic "activity by day of week and hour" grid that reveals when users are active. Annotating cells with values suits small grids; for large grids, color alone carries the pattern and numbers become clutter.

Common mistakes

  • Wrong scale type. Using a sequential scale for diverging data (or vice versa) hides the structure. Match the scale to whether the data has a meaningful midpoint.
  • Rainbow palettes. They imply an order that does not exist and fail colorblind readers. Use sequential or diverging.
  • Overcrowding with numbers. Annotating a huge grid buries the pattern under text. Annotate only small grids.
  • Using color where precision matters. Color is read imprecisely; if the reader needs exact comparisons of a few items, use bars instead.
  • Unsorted rows and columns. Ordering rows and columns by value or clustering similar ones together makes patterns far easier to see than an arbitrary order.

In interviews

Heatmaps come up when interviewers ask how you would explore relationships among many variables, or how you would present a two-dimensional summary. A strong answer names the correlation heatmap for feature exploration, explains the diverging scale centered at zero, and notes that color is a weaker channel so you would confirm interesting pairs with scatter plots. Mentioning colorblind-safe palettes and sorting rows and columns shows attention to real-world readability.

Where this fits in your learning path

The heatmap is the two-dimensional tool in the choosing the right chart framework and depends heavily on the color decisions in color in data visualization. As a correlation matrix it scales up the pairwise relationships you would otherwise explore one at a time with a scatter plot. Reading dense grids of data is a valuable exploratory skill on the data analyst roadmap and across the data analytics hub.

Frequently Asked Questions

What is a heatmap used for?
A heatmap shows how a single numeric value varies across two categorical dimensions by mapping the value to color in a grid. It is ideal for correlation matrices, cross-tabulations such as sales by month and region, and any dense table where color reveals patterns faster than reading numbers.
What color scale should a heatmap use?
Match the scale to the data. Use a sequential scale (light to dark of one hue) for values that go from low to high. Use a diverging scale (two hues meeting at a neutral middle) when the value centers on a meaningful midpoint like zero, such as a correlation or a change from a baseline.
How do I read a correlation heatmap?
Each cell shows the correlation between the two variables of its row and column, from -1 to 1. Strong positive correlations and strong negative ones stand out as the most saturated colors on a diverging scale, while near-zero cells sit near the neutral midpoint. The diagonal is always 1.
When should I not use a heatmap?
Avoid a heatmap when precise values matter more than pattern, because color is read less accurately than position or length. For comparing a handful of categories, a bar chart is clearer. Heatmaps also fail if the grid is tiny, where a plain labeled table communicates better.
Should I annotate heatmap cells with numbers?
Annotating cells with their values combines the fast pattern reading of color with the precision of numbers, which is helpful for small to medium grids. For very large grids the numbers become unreadable clutter, so rely on color alone and let the reader hover or drill down for exact values.

Want to Build Your Career in Data Analytics with AI?

Join CodeBegun and train with working industry engineers — See the Data Analytics course in Hyderabad

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 16 July 2026 LinkedIn
Chat with us