📦 Seaborn Box Plot
Last Updated: 07 Nov 2025
A box plot shows the distribution, spread, and outliers of a numeric variable. It summarizes data using:
- Minimum
- 25% (Q1)
- Median (Q2)
- 75% (Q3)
- Maximum
Hinglish Tip 🗣: Box plot ek glance me data ka spread + outliers dono dikha deta hai.
Basic Syntax
sns.boxplot(data=df, x='category', y='numeric')
plt.show()
📘 Example Dataset
df = sns.load_dataset('tips')
df.head()
📊 Basic Box Plot
sns.boxplot(data=df, x='day', y='total_bill')
plt.show()
Important Parameters
data,x,yColumns for category (x) and numeric (y).hueSplit box plots by category.
sns.boxplot(data=df, x='day', y='total_bill', hue='sex')
plt.show()
paletteChange colors.
sns.boxplot(data=df, x='day', y='total_bill', palette='coolwarm')
plt.show()
orderControl category order.
sns.boxplot(data=df, x='day', y='total_bill', order=['Thur','Fri','Sat','Sun'])
plt.show()
hue_orderOrder for hue variable.
sns.boxplot(data=df, x='day', y='total_bill', hue='sex', hue_order=['Female','Male'])
plt.show()
widthControl width of each box.
sns.boxplot(data=df, x='day', y='total_bill', width=0.3)
plt.show()
saturationColor intensity.
sns.boxplot(data=df, x='day', y='total_bill', saturation=0.5)
plt.show()
showfliersShow/hide outliers.
sns.boxplot(data=df, x='day', y='total_bill', showfliers=False)
plt.show()
fliersizeChange size of outlier points.
sns.boxplot(data=df, x='day', y='total_bill', fliersize=4)
plt.show()
⭐ Full Example
sns.boxplot(
data=df,
x='day',
y='total_bill',
hue='sex',
palette='viridis',
order=['Thur','Fri','Sat','Sun'],
hue_order=['Female','Male'],
width=0.5,
saturation=0.7,
showfliers=True,
fliersize=5
)
plt.show()
Quick Practice
- Load
penguinsdataset. - Create boxplot for
speciesvsbody_mass_g. - Add hue for
sex. - Hide fliers.
- Change width to 0.3.