Skip to content

Bar Plots in Seaborn

Seaborn’s barplot typically plots:

  • An aggregate (default is mean)
  • An uncertainty interval (confidence interval)

This is different from Matplotlib bars where you usually plot raw totals.

diagram How barplot builds one bar mermaid
Every row in a category gets averaged into one bar height, plus a confidence interval line on top.
Seaborn barplot
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.barplot(data=tips, x="day", y="total_bill")
plt.title("Mean total bill by day")
plt.tight_layout()
plt.show()
barplot with hue
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.barplot(data=tips, x="day", y="total_bill", hue="sex")
plt.title("Mean total bill by day and sex")
plt.tight_layout()
plt.show()
Custom estimator
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.barplot(data=tips, x="day", y="total_bill", estimator=np.median)
plt.title("Median total bill by day")
plt.tight_layout()
plt.show()

The whisker on top of each bar is the confidence interval — it tells you how much the average might wobble if you resampled the data:

sketch Bars with confidence-interval error bars p5.js
Bar height is the group mean; the whisker on top shows the uncertainty around that mean.
  • Use barplot for comparing group summaries.
  • Use countplot when you want raw counts.
  • If you already aggregated your data with Pandas, consider Matplotlib bars.

Continue to Count Plots for a simpler case: bars that just count rows per category, no aggregation needed.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading