Imagine that you have just finished building a regression model to predict missing well log data You then check how well it has performed on an actual vs predicted scatter plot (also known as a crossplot in petrophysics).
The result may look convincing, with a dense cloud of data points following the trend of the one-to-one line and hugging close to it. However, a large portion of those points are likely sitting directly on top of each other. Therefore, what may look like a reassuring cloud to begin with, may be systematically wrong across a whole range of values. From this chart alone and without further tweaks to the plot, it can become difficult to tell.
This is a case of overplotting, and it’s one of the common ways that a simple scatter plot can become an unreadable mess.
This does not mean that the data and the plot are entirely usless. There are a few fixes we can make to the scatter plot to help clear things up, such as switching to other styles of visualisation within the bounds of the scatter plot in order to understand the underlying relationship between the actual and predicted data.
We will see some of those fixes in this article. Also, one thing to note, even though this article focuses on actual vs predicted data, the reuls and ideas can equally apply to any scatter plot.
Setting Up a Stand-In Dataset
To illustrate overplotting we will create some synthetic well data that will allow us to display a predicted versus measured scatter plot (also known as a crossplot in petrophysics, hence the name make_crossplot_data). Here most of the points will fall in a broad cloud along the one-to-one line, with a tighter secondary concentration of data points that we will deliberately bury inside it.
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(42)
def make_crossplot_data(n):
n_main = int(n * 0.7)
n_knot = n - n_main
measured_main = rng.normal(0.15, 0.05, n_main)
measured_knot = rng.normal(0.22, 0.012, n_knot) # the hidden concentration
measured = np.concatenate([measured_main, measured_knot])
predicted = measured + rng.normal(0, 0.02, n) # model error around 1:1
measured = np.clip(measured, 0, 0.35)
predicted = np.clip(predicted, 0, 0.35)
return measured, predicted
LIMS = (0, 0.35)
def style_axes(ax):
ax.set_xlim(*LIMS)
ax.set_ylim(*LIMS)
ax.set_xlabel(”Measured porosity”)
ax.set_ylabel(”Predicted porosity”)
ax.plot(LIMS, LIMS, color=”0.4”, lw=1, ls=”--”, zorder=0) # 1:1 line
ax.set_aspect(”equal”)With the data generated, and some plotting defaults set up, we can create our first scatter plot, one that many of us will jump to after carrying out a continuous variable prediction.
measured, predicted = make_crossplot_data(20000)
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(measured, predicted, s=10, color=”#1f3b57”)
style_axes(ax)
plt.show()
On first looking at this chart we may think this looks like a decent prediction for porosity. However, most of the points closer to the 1-to-1 line are actually sitting on top of each other.
Watching a Scatter Plot Fail
The easiest way to visualise overplotting is to watch it happen.
To do this, we will draw the same distribution at increasing sample sizes and see where the scatter plot starts to break down.
First, we start small with a hundred points. At this level, we can see that the scatter plot is doing it’s job well. We are able to see individual observations, judge the spread, and pick out anything unusual.
m100, p100 = make_crossplot_data(100)
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(m100, p100, s=25, color=”#1f3b57”)
style_axes(ax)
plt.show()
If we push it to a thousand points, the chart still holds up, but the densest region is starting to merge together, which makes it difficult to count the individual observations in there. However, the overall shape of the data remains readable, for the most part.
m1k, p1k = make_crossplot_data(1000)
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(m1k, p1k, s=15, color=”#1f3b57”)
style_axes(ax)
plt.show()Now, if we increase it to twenty thousand points, the chart fails.
The centre becomes a uniform dark blue blob with many overlapping observations. And as a result, any structure that existed within that blob has now become invisible.
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(measured, predicted, s=10, color=”#1f3b57”)
style_axes(ax)
plt.show()
Why This Happens
Each observation gets its own visible mark on the scatter plot. Once two markers occupy the same pixels, the second one adds no information and sits on top of it. The hundredth point on the same position adds none either. Dense regions start to saturate early and then hide everything that arrives afterwards, which means the regions where most of your data lives are precisely the regions you can see least clearly. Meanwhile, if we have a single stray outlier at the edge of the plot, it remains perfectly visible and can draw far more attention from the reader than its importance deserves.
There is no universal point count where this issue kicks in and it will depend on the size of the markers, figure dimensions, screen resolution and, most of all, how many data points there are concentrated close together.
A tight bivariate relationship can saturate with a few thousand points, whilst a more diffuse one might last far longer before it becomes saturated and we lose any meaningful pattern or structure.
What we need to watch for is: if you can no longer distinguish individual observations in the densest region,the chart can no longer answer the question we initially set out to answer.
Temporary Fix: Transparency and Marker Size
The usual first response to improving this is to make the markers semi-transparent. Overlapping points then stack visually, so denser regions render darker and you get a crude signal for data density.
fig, ax = plt.subplots(figsize=(6, 6))
ax.scatter(measured, predicted, s=10, color=”#1f3b57”, alpha=0.1)
style_axes(ax)
plt.show()
This can help for a while. Ten overlapping points at ten per cent opacity already render as effectively solid, so the darkness scale saturates quickly. You can, however, distinguish sparse data from dense data, but not dense from very dense.
To buy us more headroom, we can shrink the markers and reduce the impact of overlapping data points. This may work for datasets in the low thousands. However, beyond that, both tricks run into the same issue: a finite number of pixels and far more observations than pixels to put them in.
Sub-Sampling: Honest but Lossy
Another option is to plot a random sample of the data rather than the full dataset. Draw a couple of thousand points from a couple of hundred thousand and the scatter plot becomes readable again. This might mean we are only displaying 10% of the full data volume.
For quick exploration this may be a reasonable move, however, the cost is that you’ve thrown away most of your data to make the chart legible.
Rare behaviour, small clusters and sparse outliers may easily be removed and become less prominent when the chart is drawn. Sampling is a workaround for the display problem, rather than a solution to it.
The Real Fix: Ask About Density Instead
Everything so far tries to preserve the original question, “where are my individual observations”, in a situation where it can no longer be answered. The better move is to change the question to “where is my data concentrated”.
This is what a hexbin plot does.
The hexbin plot divides the plotting area into hexagonal cells, counts the observations falling into each one, and maps the count to colour. No overlap is possible, because nothing is drawn per observation. Dense regions are no longer hidden, instead they become the brightest cells on the chart.
fig, ax = plt.subplots(figsize=(6, 6))
hb = ax.hexbin(measured, predicted, gridsize=40, cmap=”viridis”,
mincnt=1, extent=(*LIMS, *LIMS))
ax.plot(LIMS, LIMS, color=”0.7”, lw=1, ls=”--”, zorder=3)
ax.set_xlim(*LIMS); ax.set_ylim(*LIMS)
ax.set_xlabel(”Measured porosity”); ax.set_ylabel(”Predicted porosity”)
ax.set_aspect(”equal”)
fig.colorbar(hb, ax=ax, label=”count”, shrink=0.8)
plt.show()
If we look at the bright cell just above the middle of the one-to-one line, that’s the secondary concentration we built into the data at the start. This was what we lost when we displayed the vast number of points earlier. Here, the hexbin surfaces it without any special effort.
Using a hexbin plot does come with a trade-off, in that you lose individual observations, and you can no longer point at a specific well or sample. Outliers can become single faint cells that’s easy to miss.
Choosing the right bin size also matters. If the cells are too large smear then the underlying structure is not there any more, whereas cells that are too small reintroduce noise. For the core task of understanding where a large dataset really lives on the plot, then the hexbin chart can help with that.
Density Contours
Where the underlying data is continuous, kernel density estimation offers a related view.
Instead of counting points in cells, it estimates a smooth density surface and draws it as contour lines or filled bands, much like elevation contours on a map.
from scipy.stats import gaussian_kde
xy = np.vstack([measured, predicted])
kde = gaussian_kde(xy)
xx, yy = np.mgrid[LIMS[0]:LIMS[1]:200j, LIMS[0]:LIMS[1]:200j]
density = kde(np.vstack([xx.ravel(), yy.ravel()])).reshape(xx.shape)
fig, ax = plt.subplots(figsize=(6, 6))
cf = ax.contourf(xx, yy, density, levels=10, cmap=”viridis”)
ax.set_xlim(*LIMS); ax.set_ylim(*LIMS)
ax.set_xlabel(”Measured porosity”); ax.set_ylabel(”Predicted porosity”)
ax.set_aspect(”equal”)
fig.colorbar(cf, ax=ax, label=”density”, shrink=0.8)
plt.show()Contours are great for describing the overall shape of a distribution and for overlaying two groups on the same axes, something that can become impossible when using saturated scatter plots.
However, one thing to bear in mind is the smoothing is also the weakness. KDE can paint density into regions where no data exists, which matters if your variables have hard physical limits, such as a porosity that can’t go below zero. Treat contours as a description of shape, and check the edges against the raw data.
When You Have Millions of Points
If you truly have a large dataset, for example in the millions and beyond, tools like Datashader can be useful to explore. Rather than drawing markers at all, they aggregate the data into an image directly, computing a value per pixel. Every observation contributes to the overall picture with nothing
You Don’t Need Big Data to Have This Problem
Most discussions of overplotting treat it as a big data problem. It can also appear, and often more severely, when your values are discrete.
Well log data is a good example. A gamma ray curve recorded to the nearest whole API unit could contain the same value thousands of times across a field. On a crossplot, every one of those observations lands on exactly the same coordinates. Not nearly the same pixel, but actually the same pixel. A chart with only three thousand points can be badly overplotted if those points take a few hundred distinct value pairs, and you’ll see the same effect with any rounded measurement, integer counts, categorical codes plotted numerically, and sensor data with limited resolution.
n = 3000
base = rng.normal(0, 1, n)
gr1 = np.round(np.clip(70 + 12 * base + rng.normal(0, 6, n), 40, 110)).astype(int)
gr2 = np.round(np.clip(70 + 12 * base + rng.normal(0, 6, n), 40, 110)).astype(int)
fig, axes = plt.subplots(1, 2, figsize=(12, 6))
axes[0].scatter(gr1, gr2, s=12, color=”#1f3b57”)
axes[0].set_title(”Scatter: 3,000 points on a grid”)
axes[0].set_xlabel(”GR curve A (API)”); axes[0].set_ylabel(”GR curve B (API)”)
axes[0].set_aspect(”equal”)
hb = axes[1].hexbin(gr1, gr2, gridsize=30, cmap=”viridis”, mincnt=1)
axes[1].set_title(”Hexbin: where the weight actually is”)
axes[1].set_xlabel(”GR curve A (API)”); axes[1].set_ylabel(”GR curve B (API)”)
axes[1].set_aspect(”equal”)
fig.colorbar(hb, ax=axes[1], label=”count”, shrink=0.8)
plt.show()
This case here is sneakier than the large data point version, because the number of points being plotted gives you no warning.
The chart could look sparse enough to trust, and adjusting the transparency of the points can help a little or even some point jittering (adding small random offsets to separate identical values, although it means plotting data that doesn’t quite exist).
Using a density view can handle that more cleanly.
Summary
A scatter plot answers the question: “where are my individual observations?” That’s a good question to have when every observation is visible.
However, once observations start disappearing underneath each other, whether from the sheer volume of data or from repeated discrete values, the chart is no longer answering that question. You may try changing the styling, however, that may not be enough.
At that point, you should stop asking where the data points are and start asking where the data is concentrated. This is where hexbin plots, density contours, or a separate aggregation tool, can show you what the blob was hiding.
Overplotting is one way a default chart hides your data, but it isn’t the only one. A boxplot does the same job on a distribution, reducing it to five numbers so a bimodal formation with a gap in the middle can look like an ordinary spread. Over on Substack I build a raincloud plot one layer at a time, stacking the density, the raw points and the boxplot summary so you can see the shape and check it against the actual observations.
→ From Boxplot to Raincloud: Building a Better Distribution Plot in Python




