Skip to content
Graph Craft

2D Density / Contour

FacebookX
Example: Order time vs. price per order for 900 orders (made-up data)Plotly.js

Variant: Standard

Made-up data, for demonstration only

Variants

4 types · click one to see it in the frame above
Difference from standard
The recommended type; use it as a starting point
Use when
See the intensity of a two-dimensional distribution

2D Density Plot is a chart that estimates where the points of two variables are packed most tightly, and shows it with contour lines (like height lines on a map) or with colour. This example uses 900 orders (made-up data). The horizontal axis is the time of the order and the vertical axis is the price per order. The dark areas, with contour lines drawn over the data points, are where orders cluster most.

How to read a 2D Density Plot

  • Each contour line is one level of density. Points on the same line have the same density.
  • An inner closed loop may enclose a very dense area. It does not mark the centre of all the data. The closer the lines sit, the faster the density changes.
  • Look at the direction of the dense area. If the main axis tilts up to the right, the two variables may rise together. Check the data points as well.
  • Count the peaks. This example has two clusters: orders around 12:30 at about $180, and orders around 19:30 at about $320. The first cluster is bigger (about two thirds of the orders).
  • Compare with the real points. Try the "No data points" and "Contour lines only" variants to see the difference between the overview and the raw data.

When to use it

  • There are so many points that they overlap in a scatter plot. A 2D distribution avoids overplotting and may reveal hidden patterns.
  • Density changes slowly. Contour lines work well when density changes gradually along both axes.
  • You compare clearly separate groups. You can draw contours in different colours, but lines from many groups that overlap a lot are hard to read.

When not to use it

  • There is little data. Use it when you have a lot of data. If the points do not overlap, use a Scatter Plot.
  • You need the real count in each area. Use a Hexbin Plot, which counts the real number of points.
  • Readers are not used to contour lines. Explain them first, or use a plain colour fill.

Common mistakes

1. Not trying different estimation settings

This family of charts is sensitive to cell size or bandwidth. Different values can show different patterns. This example builds the contours from a 2D histogram. Try the "Fewer levels" variant to see the effect of the number of contour levels.

2. Reading the contours as raw data

Contours summarise the data in an area. They are not individual observations. This example builds the contours by counting points in 2D cells and then showing the levels, so do not read a contour as the exact number of orders at one position.

3. Drawing many groups until they overlap

The lines can tangle until you cannot read each group's pattern.

4. Using a rainbow palette

Choose a colour palette that is easy to read.

5. Hiding outliers

Contours swallow points that sit far away. If the outliers matter, show the points as well.

Compared with similar charts

ChartHow it differsChoose it when
2D Density PlotEstimates density, smoothThere is a lot of data and you want a smooth shape
Hexbin PlotReal counts in hexagonal cellsYou want the real counts
Scatter PlotRaw pointsThere is little data
Density PlotDensity of one variableThere is only one variable

Frequently asked questions

How is a 2D density plot different from a contour plot?

A contour plot uses lines to join positions that have the same value. If that value is the density of points, it is one way to show a 2D density. But a contour plot also works for other values.

How many data points does it need?

It suits a lot of data. If you do not have much, a plain scatter plot is enough.

Can I use 3D?

This is one of the rare cases where 3D (a surface plot) may be worth it, but watch out for how the rotated view misleads.

References

  • 2D density plot · Data to Viz · www.data-to-viz.comUsed to confirm: how to read a 2D density plot and what to watch for
  • Fundamentals of Data Visualization, ch. 18: Handling overlapping points · Claus O. Wilke · clauswilke.comUsed to confirm: overlapping points, hexbins and contour lines
  • Fundamentals of Data Visualization, ch. 12: Visualizing associations among two or more quantitative variables · Claus O. Wilke · clauswilke.comUsed to confirm: associations between variables, correlation and PCA

Last updated 28 Nov 2026