HOWTO · Seaborn
How to Create Seaborn Boxplot Without Outliers
Create a Seaborn boxplot without outlier markers using showfliers=False, understand the 1.5 x IQR rule Seaborn uses to flag fliers, and see when removing or capping outlier values is justified instead.
On this page
This article aims to demonstrate what boxplot and outliers are and how to create a Seaborn boxplot without the outlier markers. In most cases the right answer is to hide the markers, not to delete data — the sections below show both, and explain when actually removing or capping values is justified.
Create a Seaborn Boxplot Without Outlier Markers
A boxplot summarizes a distribution with its quartiles: the box spans the first quartile (Q1) to the third quartile (Q3) with the median inside, and the whiskers extend to the most extreme values that are not considered outliers. Points beyond the whiskers are drawn individually as outlier markers (fliers).
We will work on the tips dataset, which is already preloaded in our Seaborn library. Let’s import the required packages and look at the data; this data set is about a restaurant with several columns.
import seaborn as sb
import matplotlib.pyplot as plt
import pandas as pd
TIPS = sb.load_dataset("tips")
TIPS.head()
Plotting the total_bill column with the defaults shows several fliers on the right:
sb.boxplot(x=TIPS["total_bill"])
plt.show()
Output:
To create the same plot without the outlier markers, pass showfliers=False:
sb.boxplot(x=TIPS["total_bill"], showfliers=False)
plt.show()
Output:
Understand What Seaborn Shows as an Outlier
Seaborn (through Matplotlib) flags a point as an outlier when it lies more than 1.5 × IQR beyond the quartiles, where the IQR is Q3 − Q1. The whiskers reach the most extreme data points still inside those fences; everything outside them is drawn as a flier.
You can reproduce the rule for total_bill with the describe() function, which reports Q1 = 13.35, the median = 17.80, and Q3 = 24.13 for this column. The IQR is therefore 10.78, so the fences are 13.35 − 1.5 × 10.78 = −2.82 and 24.13 + 1.5 × 10.78 = 40.30. Nine of the 244 bills lie above the upper fence (the maximum is 50.81), and those nine points are exactly the fliers in the first plot. Note that they are not data errors — they are simply the largest bills in the restaurant’s records.
Hide Outlier Markers with showfliers=False
showfliers=False changes only what is drawn. The box, median, and whiskers are computed from the full data, including the outliers, exactly as before; the flier markers are simply not rendered. The plot also no longer stretches to accommodate the far-out points, so the box and whiskers become easier to read.
Choose this option when the outliers are valid data and your goal is presentation — for example, when a few extreme values compress the rest of the plot. Nothing about your dataset or your statistics changes, so there is nothing extra to justify or disclose.
Remove or Cap Outlier Values Only When the Analysis Requires It
Sometimes the analysis itself — not just the picture — has to change: a sensor glitch, a data-entry error, or a model that is distorted by a handful of extreme values. Only then should you alter the values, and the statistics you report afterwards must be computed on the altered data and described as such.
To remove the outliers, filter with the same fences Seaborn uses (not with the quartile values themselves — filtering to the range between Q1 and Q3 would discard a quarter of your valid data on each side):
q1 = TIPS["total_bill"].quantile(0.25)
q3 = TIPS["total_bill"].quantile(0.75)
iqr = q3 - q1
filtered = TIPS[(TIPS["total_bill"] >= q1 - 1.5 * iqr) & (TIPS["total_bill"] <= q3 + 1.5 * iqr)]
sb.boxplot(x=filtered["total_bill"])
plt.show()
To cap (winsorize) the outliers instead — keeping every row, but pulling the extreme values in to the fences — use clip:
capped = TIPS["total_bill"].clip(lower=q1 - 1.5 * iqr, upper=q3 + 1.5 * iqr)
sb.boxplot(x=capped)
plt.show()
Output:
Both operations change the data: removal drops the 9 largest bills entirely, and capping rewrites them to 40.30. Use them when you have a reason to distrust or bound those values — and if all you wanted was a cleaner chart, go back to showfliers=False and leave the data alone.