Skip to content

Box Plots and Whiskers

Box plot recap

Box plots show:

  • Median (middle line)
  • Q1 and Q3 (box)
  • Spread (IQR)
  • Outliers (points)

They are excellent for comparing a numeric variable across categories.

Seaborn boxplot

Boxplot
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.boxplot(data=tips, x="day", y="total_bill")
plt.title("Total bill by day")
plt.xlabel("Day")
plt.ylabel("Total bill")
plt.tight_layout()
plt.show()
Boxplot
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.boxplot(data=tips, x="day", y="total_bill")
plt.title("Total bill by day")
plt.xlabel("Day")
plt.ylabel("Total bill")
plt.tight_layout()
plt.show()

Add hue for a second grouping

Boxplot with hue
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.boxplot(data=tips, x="day", y="total_bill", hue="sex")
plt.title("Total bill by day and sex")
plt.tight_layout()
plt.show()
Boxplot with hue
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.boxplot(data=tips, x="day", y="total_bill", hue="sex")
plt.title("Total bill by day and sex")
plt.tight_layout()
plt.show()

Tips

  • Treat outliers as signals, not always as errors.
  • If you need to see the raw points, add stripplotstripplot.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did