📊 Seaborn Bar Plot

Last Updated: 07 Nov 2025


A bar plot shows the average value of a numerical column for each category.

Hinglish Tip 🗣: Category ke hisaab se average compare karna ho (jaise day-wise average bill), bar plot best.


Basic Syntax

sns.barplot(data=df, x='category_col', y='numeric_col')
plt.show()

📘 Example Dataset

df = sns.load_dataset('tips')
df.head()

📊 Basic Bar Plot

sns.barplot(data=df, x='day', y='total_bill')
plt.show()

Important Parameters

  • data, x, y Dataset and columns to visualize.
  • hue Split each bar by category.
sns.barplot(data=df, x='day', y='total_bill', hue='sex')
plt.show()
  • estimator By default, Seaborn uses mean. You can change it to sum, count, etc.
from numpy import median
sns.barplot(data=df, x='day', y='total_bill', estimator=median)
plt.show()
  • ci (Confidence Interval) Remove the vertical error bars.
sns.barplot(data=df, x='day', y='total_bill', ci=None)
plt.show()
  • palette Custom color theme.
sns.barplot(data=df, x='day', y='total_bill', palette='magma')
plt.show()
  • order Control category order.
sns.barplot(data=df, x='day', y='total_bill', order=['Thur', 'Fri', 'Sat', 'Sun'])
plt.show()
  • hue_order Custom order for hue.
sns.barplot(data=df, x='day', y='total_bill', hue='sex', hue_order=['Male', 'Female'])
plt.show()
  • saturation Bar color intensity.
sns.barplot(data=df, x='day', y='total_bill', saturation=0.4)
plt.show()
  • errorbar Control error bar style (new Seaborn versions).
sns.barplot(data=df, x='day', y='total_bill', errorbar=('ci', 95))
plt.show()

⭐ Full Example

sns.barplot(
    data=df,
    x='day',
    y='total_bill',
    hue='sex',
    estimator=sum,
    ci=None,
    palette='coolwarm',
    saturation=0.8,
    order=['Thur','Fri','Sat','Sun'],
    hue_order=['Female','Male']
)
plt.show()

Quick Practice

  1. Use penguins dataset.
  2. Make a barplot of species vs body_mass_g.
  3. Add a hue for sex.
  4. Change estimator to median.
  5. Remove CI.