Binned scatterplot: a scatterplot for thousands of points

Updated

A binned scatterplot is a scatterplot for large datasets. Instead of drawing every point, it divides the plane into a grid of small bins, rectangles or hexagons, counts the points in each, and colors each bin by its count. Where an ordinary scatterplot of thousands of points turns into a solid blob, the binned version shows where the data are dense and where they are sparse, like a two-dimensional histogram.

When to use it

  • You have thousands or millions of paired readings, such as in-line gauge data, sensor logs or test-stand records.
  • An ordinary scatterplot is saturated: points overlap so much that 10 and 1,000 points in the same spot look the same.
  • You want to see both the main relationship and small groups of unusual points that a blob would hide.
  • You want to summarize how the average of Y changes across X when there are far too many points to judge by eye.

How it works

  1. Choose a bin size along each axis. As with a histogram, bins that are too large hide structure and bins that are too small leave most bins with 0 or 1 point.
  2. Count the points falling in each bin.
  3. Color each bin by its count on a sequential scale, light for few and dark for many. Leave empty bins blank. When counts range over several orders of magnitude, a logarithmic color scale keeps sparse regions visible.
  4. Hexagonal bins are a common alternative to rectangles: they tile the plane with less visual bias along the axes.

A related plot, sometimes also called a binned scatterplot, bins only the X axis and plots the mean of Y in each X bin. It shows the shape of the average relationship without the scatter. Both views help, and the example below uses both.

Example

A boring machine finishes a bore with a tolerance of ±10 µm. An in-process gauge logs the deviation from nominal for every part, together with the spindle temperature. Two weeks of production give 2,400 pairs. A plain scatterplot shows a dark diagonal smear with a few loose points at the left. The binned version, with 3 °C by 4 µm bins, counts:

Deviation (µm) \ Temperature22 to 25 °C25 to 28 °C28 to 31 °C31 to 34 °C34 to 37 °C
8 to 1200010
4 to 8003014411
0 to 422250466014
−4 to 0321024851861
−8 to −493483130
−12 to −8301000
Parts1571731,05099426

Colored by count, the grid shows:

  • The main mass in two bins: 504 parts at 28 to 31 °C and 660 at 31 to 34 °C, both with deviations of 0 to 4 µm. Nearly half of all parts (48.5%) fall in these two bins, which a plain scatterplot cannot show because the points there are drawn on top of each other.
  • A diagonal band. Dense bins step up and to the right: at higher temperatures, the bore comes out larger.
  • A sparse tail to the lower left. 330 parts were made below 28 °C, mostly in the first hour after each start-up. Among them are all 31 parts below −8 µm, and 5 of those are beyond the −10 µm limit.

The average deviation in each temperature column makes the trend explicit: −5.96, −2.73, 0.03, 1.84 and 3.43 µm from the coldest to the warmest column. A least-squares line through all 2,400 points has a slope of 0.90 µm per °C, and the correlation is 0.737. The spindle grows with heat, and parts made before it warms up are undersized.

Two actions follow: a warm-up cycle before production starts, and possibly a thermal compensation of about −0.9 µm per °C in the machine control. Both target the tail the binned plot revealed.

How to read the results

  • Darkest bins show where most of the data lie, the normal operating point.
  • The direction of the dense band shows the relationship, just as in a scatterplot.
  • Isolated light bins away from the band are small groups or outliers worth tracing.
  • The color legend tells you how many points a shade represents; check whether it is linear or logarithmic.
  • Column or row averages summarize the relationship when the cloud is too wide to judge by eye.

Common mistakes

  • Bins too big. A 3 × 3 grid of a curved relationship looks like a blob. Try finer bins.
  • Bins too small. With most bins holding a single point, the plot looks like a noisy scatterplot again.
  • A linear color scale for very uneven counts. One bin with 5,000 points makes every bin under 100 look empty. Use a logarithmic scale.
  • Forgetting that a dense region is not a good region. Density shows where the process runs, not where it should run. Compare with the specification.
  • Mixing sources. Two machines in one plot can make two overlapping bands; color or split by source.

Frequently asked questions

What is the difference between a binned scatterplot and a heatmap?

They look alike. A binned scatterplot bins two continuous variables and colors by count. A heatmap colors a table whose rows and columns are often categories, and its cells can hold any value, such as a rate or a mean.

When should I use hexagonal bins?

When you want a smoother picture. Hexagons fit together without the strong horizontal and vertical edges of rectangles, so diagonal patterns look more natural. Rectangles are easier to tabulate, as in the example.

How many points do I need for a binned scatterplot?

It pays off from a few thousand points. Below a few hundred, an ordinary scatterplot, perhaps with semi-transparent points, shows more.

Can I still compute a correlation or a regression?

Yes, on the original data, not on the bins. Binning is only for the picture. See correlation and regression.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab