📦 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, y Columns for category (x) and numeric (y).
  • hue Split box plots by category.
sns.boxplot(data=df, x='day', y='total_bill', hue='sex')
plt.show()
  • palette Change colors.
sns.boxplot(data=df, x='day', y='total_bill', palette='coolwarm')
plt.show()
  • order Control category order.
sns.boxplot(data=df, x='day', y='total_bill', order=['Thur','Fri','Sat','Sun'])
plt.show()
  • hue_order Order for hue variable.
sns.boxplot(data=df, x='day', y='total_bill', hue='sex', hue_order=['Female','Male'])
plt.show()
  • width Control width of each box.
sns.boxplot(data=df, x='day', y='total_bill', width=0.3)
plt.show()
  • saturation Color intensity.
sns.boxplot(data=df, x='day', y='total_bill', saturation=0.5)
plt.show()
  • showfliers Show/hide outliers.
sns.boxplot(data=df, x='day', y='total_bill', showfliers=False)
plt.show()
  • fliersize Change 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

  1. Load penguins dataset.
  2. Create boxplot for species vs body_mass_g.
  3. Add hue for sex.
  4. Hide fliers.
  5. Change width to 0.3.