CorrelationAdvanced

Contour Plot

Smooth curves of equal density that map the landscape of a bivariate distribution — like topographic lines for your data.

// 01 — The chart

What it looks like

Example — Height vs. weight distributionn = 5,000 adults
120kg80kg40kg150cm175cm200cmHeightWeight

A contour plot showing the 2D density distribution of height and weight. Innermost contour = highest density (the most common combination). The elliptical shape reveals a positive correlation.

// 02 — Definition

What is a contour plot?

A contour plot (also called a 2D density plot or isoline plot) uses smooth curves to connect points of equal density in a two-variable distribution. Think of it as a topographic map where the “mountains” are areas of highest data concentration and the “valleys” are where data is sparse.

Each contour line represents a specific density level. The innermost contour encircles the densest region (the peak of the distribution), while outer contours enclose progressively lower-density areas. The spacing between contours tells you how steeply density changes.

Contour plots are created using kernel density estimation (KDE), which smooths the raw data points into a continuous probability surface. This makes them ideal for revealing the underlying shape of distributions that discrete binning methods (like hexbin) can miss.

Topographic analogy: Just as contour lines on a map connect points of equal elevation, density contours connect points of equal data density. Closely spaced contours mean rapid density change; widely spaced ones mean gradual change.

// 03 — Anatomy

Parts of a contour plot

ABCDE
A — Y-axis: One of the two continuous variables
B — X-axis: The second continuous variable
C — Peak (innermost contour): The densest region — most data points concentrate here
D — Outer contour: Lower-density boundary — encompasses the spread of the distribution
E — Contour spacing: Close contours = steep density gradient; wide = gentle gradient

// 04 — Usage

When to use it — and when not to

✓Use a contour plot when…
  • You want to see the smooth shape of a 2D distribution, not discrete bins
  • Comparing the density peaks of different groups overlaid on the same axes
  • Identifying multimodal distributions — separate peaks in the density surface
  • You need to show whether the distribution is symmetric, skewed, or elongated
  • Exploring the joint distribution of two variables before modeling
  • Publishing scientific or academic work where smooth KDE is standard
×Avoid a contour plot when…
  • You have very few data points — KDE needs enough data for reliable smoothing
  • Exact counts in specific regions matter more than shape — use hexbin instead
  • Your audience isn’t familiar with density estimation concepts
  • You want to show individual data points — contour hides them
  • The data has sharp boundaries or discontinuities that KDE will blur
  • One or both variables are categorical — contours only work with continuous data

// 05 — Reading guide

How to read a contour plot

Follow these steps whenever you encounter a contour plot.

1

Find the peak(s)

Look for the innermost contour — that’s where data is densest. If there are multiple inner contours in different locations, the distribution is multimodal.

2

Read the contour shape

Circular contours suggest no correlation between variables. Elongated ellipses indicate correlation — tilted up-right = positive, up-left = negative.

3

Check contour spacing

Closely packed contours mean density drops off sharply (a tight distribution). Widely spaced contours mean gradual tails.

4

Look for asymmetry

If contours are wider on one side, the distribution is skewed in that direction. This reveals information about the tail behavior.

5

Compare overlaid groups

When multiple groups are shown, look at how their contours overlap or separate — shared peaks mean similar distributions, separated peaks mean distinct populations.

// 06 — Data format

What your data should look like

Same as a scatter plot — two continuous columns. The density surface is estimated from the raw point cloud using kernel density estimation.

// Point cloud data

| height_cm | weight_kg |

|-----------|-----------|

| 175       | 78       |

| 162       | 55       |

| 188       | 92       |

// 07 — Construction

How to build one

1.

Compute the 2D kernel density estimate (KDE) — place a Gaussian kernel at each data point and sum the contributions across a fine grid.

2.

Choose contour levels — select density thresholds to draw isolines. Common choices are equal-density quantiles (e.g., 10%, 25%, 50%, 75%, 90%).

3.

Extract contour lines at each threshold using a marching squares algorithm.

4.

Optionally fill between contours with graduated color to create a filled contour plot.

5.

Choose the bandwidth — this controls smoothing. Too small = noisy, too large = oversmoothed. Cross-validation can help select the optimal bandwidth.

// 08 — Pitfalls

Common mistakes

Wrong bandwidth selection

Too narrow a bandwidth creates spiky, noisy contours; too wide blurs distinct peaks into a single blob. Always try multiple bandwidths.

Implying density where there’s no data

KDE smoothing can extend contours into impossible regions (e.g., negative weights). Truncate or clip contours at domain boundaries.

Too many contour levels

More than 8–10 levels creates visual clutter. Fewer, well-chosen levels are clearer.

Ignoring sample size effects

With small samples, KDE contours can be misleading — the smooth surface implies more information than the data contains.

Not showing the raw data

Layering a scatter plot underneath contours lets readers verify the smoothed estimate against actual data points.

// 09 — In the wild

Real-world examples

Meteorology

Weather services use contour plots to show pressure surfaces, temperature distributions, and precipitation probability across geographic regions.

Machine learning

Decision boundary visualization overlays contour plots on training data to show where a classifier places its boundaries between predicted classes.

Ecology

Species distribution modeling uses contour density plots to show where animal populations are most concentrated based on GPS tracking data.

// 10 — At a glance

Quick reference

Also known as

2D density plot, isoline plot, level plot

Category

Correlation / Distribution

Typical data

Two continuous variables, large n

Best for

Smooth density shape visualization

Difficulty

Advanced

Key parameter

KDE bandwidth

// 11 — Accessibility

Making it accessible

Label contour levels with numeric density values where space permits

Use colorblind-safe gradients for filled contours (viridis, cividis)

Provide text descriptions of peak locations and distribution shape

Vary line style (solid, dashed, dotted) across contour levels for non-color differentiation

Include a summary for screen readers: number of peaks, orientation, spread

// 12 — Variations

Common variations

Filled contour

Colors the space between contour lines instead of showing just the outlines — creates a heatmap-like effect.

Contour + scatter overlay

Plots raw data points on top of contours to show both the smoothed estimate and individual observations.

Multi-group contours

Overlays contours from different groups (e.g., male/female) in different colors to compare distributions.

3D surface plot

Renders the density surface as a 3D mountain rather than a 2D projection — more dramatic but harder to read precisely.

// 13 — FAQs

Frequently asked questions

What is a contour plot?+

A contour plot (also called a 2D density plot or isoline plot) uses smooth curves to connect points of equal density in a two-variable distribution. Think of it as a topographic map where the "mountains" are areas of highest data concentration and the "valleys" are where data is sparse.

When should you use a contour plot?+

Use a contour plot when you want to see the smooth shape of a 2D distribution, not discrete bins. It also works well when comparing the density peaks of different groups overlaid on the same axes, and when identifying multimodal distributions — separate peaks in the density surface.

When should you avoid a contour plot?+

Avoid a contour plot when you have very few data points — KDE needs enough data for reliable smoothing. It is also a poor fit when exact counts in specific regions matter more than shape — use hexbin instead, or when your audience isn’t familiar with density estimation concepts.

What data do you need to make a contour plot?+

Same as a scatter plot — two continuous columns. The density surface is estimated from the raw point cloud using kernel density estimation.

How is a contour plot different from a hexbin plot?+

Both a contour plot and a hexbin plot can look similar at first glance, but they answer different questions. Reach for a contour plot when the comparisons and patterns it was designed to reveal match what you need to communicate, and choose a hexbin plot when its particular strengths better fit your data and audience.

What is another name for a contour plot?+

Contour Plot is also known as 2D density plot, isoline plot, level plot. The name varies between fields, but the visualisation technique is the same.

What size of dataset works best for a contour plot?+

Contour Plot works best for Smooth density shape visualization. Outside that range the chart either looks empty or becomes too cluttered to read clearly.

Are contour plots accessible to screen readers?+

Yes — a contour plot can be made accessible to screen readers by pairing it with a clear text summary of the key insight, ensuring color choices meet WCAG contrast guidelines, adding descriptive alt text or aria-label to the SVG, and offering the underlying data as an HTML table fallback for assistive technologies.