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?
What color scale should a heatmap use?
How do I read a correlation heatmap?
When should I not use a heatmap?
Should I annotate heatmap cells with numbers?
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

