Box Plots and Whiskers
Box plot recap
Section titled “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.
flowchart LR A["Sort the values"] --> B["Find Q1, median, Q3"] B --> C["Box = Q1 to Q3"] B --> D["Whiskers = in-range min/max"] B --> E["Outliers = points
beyond the whiskers"]
Seaborn boxplot
Section titled “Seaborn 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
Section titled “Add hue for a second grouping”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()Visualize it
Section titled “Visualize it”A box plot is a compact summary of a distribution’s shape. The box spans Q1 to Q3 (the middle 50% of the data), the line inside is the median, the whiskers reach to the smallest/largest values still in range, and any dots beyond are outliers:
- Treat outliers as signals, not always as errors.
- If you need to see the raw points, add
stripplot.
Continue to Violin Plots to see the full distribution shape, not just five summary numbers.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – A Basic Box Plot
Section titled “Exercise 1 – A Basic Box Plot”Exercise 2 – Split by a Second Category
Section titled “Exercise 2 – Split by a Second Category”Exercise 3 – Quartiles With Pandas
Section titled “Exercise 3 – Quartiles With Pandas”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading