Boxplots are a great statistical tool for visualising data and are commonly used during the Exploratory Data Analysis (EDA) phase of data science projects. They provide us with a quick statistical summary of the data, help us understand how data is distributed and help identify anomalous data points (outliers).
They also make it easy to compare data distributions across groups, and they are familiar enough that most technical readers can scan them without too much effort.
However, one of their problems is that they can hide most of the data behind statistics.
A simple fix is to keep the boxplot and overlay the raw points. You still get the familiar summary, but you also get to see the observations that summary leaves behind.
This article walks through that combination in Python using seaborn and matplotlib to illustrate how we can see the individual data points that make up the statistical summary of a boxplot.
What are Boxplots?
A boxplot reduces a distribution to a handful of summary statistics. That is useful, but it also means the shape of the distribution, the clustering, the gaps, and the number of observations behind each group mostly disappear.
Boxplots are a standardised way to display the distribution of data based on five key numbers:
“minimum”
1st Quartile (25th percentile)
median (2nd Quartile/ 50th Percentile)
3rd Quartile (75th percentile)
“maximum”
The minimum and maximum values are defined as Q1–1.5 * IQR and Q3 + 1.5 * IQR respectively. Any points that fall outside of these limits are referred to as outliers.

Boxplots can be used to:
Identify outliers or anomalous data points
To determine if our data is skewed
To understand the spread/range of the data
To construct a boxplot, we first start with the median value (50th percentile). This represents the middle value within our data.
A box is then formed between the 25th and 75th percentiles (Q1 and Q3 respectively). The range represented by this box is known as the interquartile range (IQR).
From this box extends two lines, which are also known as the whiskers. These extend to Q1–1.5 * IQR and Q3 + 1.5 * IQR or to the last data point if it is less than this value.
Any points that fall beyond the whisker limits are known as outliers.
I have previously written on Medium about creating boxplots, especially for well log data:
Creating Boxplots with the Seaborn Python Library
Why Adding Raw Data Points Can Help
A boxplot is good at showing the middle of the distribution and the overall spread in a compact way. It becomes less helpful when:
group sizes differ and the chart gives no real sense of how much data supports each box
values are clustered or split into sub-groups that the IQR spans but doesn’t reveal
a few high or low values stretch the whiskers in ways that look more important than they really are
Overlaying the raw points helps with all three.
You can see how many values sit behind each group, whether the distribution looks smooth or broken into pockets, and whether extreme values are isolated or part of a broader tail.
In seaborn, the quickest way to do this is with stripplot, which adds a small amount of horizontal jitter so the points don’t sit directly on top of each other. It’s not the same as a true beeswarm plot, which places points more systematically, but it is simple, effective, and often good enough for exploratory work.
Setting Up the Dataset
To make the comparison worthwhile, the synthetic data needs to contain patterns that a plain boxplot doesn’t show very clearly.
We will use three formations:
Aldwick: a fairly broad, high-porosity group
Brentford: a bimodal group made from two clusters
Castleton: a low-porosity group with a tight main cluster and a few higher values
The group sizes are also deliberately unequal.
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import pandas as pd
import numpy as np
np.random.seed(42)
aldwick = np.random.normal(0.22, 0.04, 80)
brentford = np.concatenate([
np.random.normal(0.12, 0.015, 30),
np.random.normal(0.19, 0.015, 30)
])
castleton = np.concatenate([
np.random.normal(0.075, 0.012, 45),
np.random.normal(0.13, 0.01, 5)
])
data = pd.DataFrame({
‘Formation’: (
[’Aldwick’] * len(aldwick) +
[’Brentford’] * len(brentford) +
[’Castleton’] * len(castleton)
),
‘Porosity’: np.concatenate([aldwick, brentford, castleton])
})
data[’Porosity’] = data[’Porosity’].clip(0, 0.35)This gives us three groups with different internal structure, rather than three variations of the same general shape.
Step 1: Start with a Plain Boxplot
A standard boxplot gives a useful baseline and can be generated simply using:
fig, ax = plt.subplots(figsize=(8, 5))
sns.boxplot(data=data, x=’Formation’, y=’Porosity’, ax=ax)
plt.show()At first glance, the comparison looks clean and straightforward. Aldwick has the highest median porosity, Castleton the lowest, and Brentford sits in between.
That is useful, but it doesn’t tell you much about what is happening inside each group. You can’t see that Brentford is made from two clusters, nor can you tell how many observations sit behind each box. Additionally, you can’t tell whether the values inside the IQR are evenly spread or tightly packed into parts of the range.
Step 2: Overlay the Raw Data Points
The main change is simply to add a strip plot on top of the boxplot.
One small detail matters here: set fliersize=0 on the boxplot first, otherwise the extreme values will appear twice.
fig, ax = plt.subplots(figsize=(8, 5))
sns.boxplot(
data=data,
x=’Formation’,
y=’Porosity’,
ax=ax,
width=0.4,
color=’lightgray’,
fliersize=0
)
sns.stripplot(
data=data,
x=’Formation’,
y=’Porosity’,
hue=’Formation’,
legend=False,
ax=ax,
jitter=True,
size=4,
alpha=0.5,
palette=’Set2’
)
plt.show()Now the differences are more informative.
Aldwick shows a broad cloud of values at the high-porosity end. Brentford is no longer just a mid-range box. You can see that the values gather into two bands. Castleton shows a tight low-porosity cluster with a small number of higher values above it, and a few outliers.
The summary statistics are still there, but they are no longer doing all the talking.
Step 3: Reduce Visual Clutter
With larger groups, the overlay can quickly become messy. Smaller markers and a little more transparency usually help.
fig, ax = plt.subplots(figsize=(8, 5))
sns.boxplot(
data=data,
x=’Formation’,
y=’Porosity’,
ax=ax,
width=0.4,
color=’lightgray’,
fliersize=0
)
sns.stripplot(
data=data,
x=’Formation’,
y=’Porosity’,
hue=’Formation’,
legend=False,
ax=ax,
jitter=True,
size=3,
alpha=0.4,
palette=’Set2’
)
plt.show()This version is easier to read. Dense areas begin to appear darker, which gives you a rough visual sense of where values are concentrated without needing a separate density plot.
It is still a simple chart, but it carries more of the distribution with it.
Step 4: Add Group Means
A boxplot already gives you the median. In skewed data, the mean can sit in a slightly different place, and that difference can be useful to see.
A short dashed line across each group keeps the mean marker distinct from the existing boxplot elements.
formations = [’Aldwick’, ‘Brentford’, ‘Castleton’]
fig, ax = plt.subplots(figsize=(8, 5))
sns.boxplot(
data=data,
x=’Formation’,
y=’Porosity’,
ax=ax,
width=0.4,
color=’lightgray’,
fliersize=0
)
sns.stripplot(
data=data,
x=’Formation’,
y=’Porosity’,
hue=’Formation’,
legend=False,
ax=ax,
jitter=True,
size=3,
alpha=0.4,
palette=’Set2’
)
for i, formation in enumerate(formations):
mean_val = data.loc[data[’Formation’] == formation, ‘Porosity’].mean()
ax.hlines(
mean_val,
i - 0.25, i + 0.25,
colors=’black’,
linewidths=2,
linestyles=’--’,
zorder=5
)
plt.show()This adds one more layer of context without making the chart feel busy. In Castleton, for example, the small number of higher values nudges the mean above the main cluster. That is easier to appreciate when the points are visible as well.
Step 5: Final Polish
The final version adds a few useful presentation touches:
consistent colours for each formation
n=labels beneath each grouplight horizontal gridlines
cleaner spines
a clearer title and axis labels
formation_colours = {
‘Aldwick’: ‘#2ecc71’,
‘Brentford’: ‘#3498db’,
‘Castleton’: ‘#e74c3c’
}
fig, ax = plt.subplots(figsize=(9, 6), facecolor=’white’)
sns.boxplot(
data=data,
x=’Formation’,
y=’Porosity’,
ax=ax,
width=0.4,
color=’#ecf0f1’,
fliersize=0,
linewidth=1.2
)
sns.stripplot(
data=data,
x=’Formation’,
y=’Porosity’,
hue=’Formation’,
legend=False,
ax=ax,
jitter=True,
size=3.5,
alpha=0.5,
palette=list(formation_colours.values())
)
for i, formation in enumerate(formations):
mean_val = data.loc[data[’Formation’] == formation, ‘Porosity’].mean()
ax.hlines(
mean_val,
i - 0.25, i + 0.25,
colors=’#2c3e50’,
linewidths=2,
linestyles=’--’,
zorder=5
)
n = len(data.loc[data[’Formation’] == formation])
ax.text(
i, -0.015, f’n={n}’,
ha=’center’, va=’top’,
fontsize=9, color=’#555555’
)
ax.set_xlabel(’Formation’, fontsize=12, fontweight=’bold’, labelpad=24)
ax.set_ylabel(’Porosity (v/v)’, fontsize=12, fontweight=’bold’, labelpad=10)
ax.set_title(’Porosity Distribution by Formation’, fontsize=14, fontweight=’bold’, pad=15)
ax.spines[[’top’, ‘right’]].set_visible(False)
ax.grid(axis=’y’, alpha=0.3, linestyle=’--’, linewidth=0.8)
ax.tick_params(axis=’both’, labelsize=10)
ax.set_ylim(0, 0.32)
mean_patch = mpatches.Patch(color=’#2c3e50’, label=’Group mean (dashed)’)
ax.legend(handles=[mean_patch], fontsize=9, framealpha=0.9)
plt.tight_layout()
plt.savefig(’porosity_overlay.png’, dpi=150, bbox_inches=’tight’, facecolor=’white’)
plt.show()What the Overlay Reveals
The final chart shows things that a plain boxplot only hints at.
First, the group sizes are immediately more obvious. Aldwick has more observations than Castleton, and the chart no longer makes those boxes look equally well supported.
Second, Brentford is revealed as a split distribution rather than a single smooth middle range. A plain boxplot summarises that group neatly, but it doesn’t tell you that the values are gathering into two distinct bands.
Third, Castleton shows how a small number of higher values can affect the upper part of the summary without changing the fact that most observations remain tightly clustered at the low end.
This is the real strength of the combination. It lets you keep the summary while checking what kind of data is actually producing it.
That is particularly useful in exploratory work, where similar-looking boxplots can hide very different underlying patterns.
When This Is Most Useful
This combination works best when:
you are comparing a small number of groups
the number of observations per group is not too large
you want to see whether the summary statistics are masking something important
sample size, clustering, or outliers could change how you interpret the result
It’s especially helpful as a check before deciding what kind of final figure to publish.
A plain boxplot might still be the right choice for the finished chart. But, the overlay is often the thing that tells you whether the plain boxplot is leaving too much unsaid.
Drawbacks to Keep in Mind
This approach does have limits though.
Once each group contains several hundred observations, the raw points can start to blur into clutter, even with transparency. At that point, a violin plot, KDE, or another density-based chart may communicate the shape more clearly.
Jitter also needs a little care. The horizontal spread of the points is artificial. It is there only to stop overlap, not to encode any additional meaning. If a reader treats that width as data, the chart can be misread.
There is also a judgement call around audience. For exploratory work, the extra detail is often worth it. For presentation slides or reports, it depends whether the raw points genuinely help interpretation or just make the figure busier.
If this kind of chart interests you, ridgeline plots are worth adding to your toolkit. They work particularly well when you have more groups than a box plot can comfortably handle, and you want to compare distribution shapes rather than just summary statistics.
I wrote a full walkthrough on Substack covering how to build them in matplotlib with petrophysical data:
Ridgeline Plots in Matplotlib: An Alternative to Faceted Histograms







