Skip to content

Bar Plots in Seaborn

What is barplotbarplot in Seaborn?

Seaborn’s barplotbarplot 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.

Example: mean total bill by day

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()
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()

Add hue

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()
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()

Change estimator (sum, median, etc.)

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()
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()

Visualize it

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.

Tips

  • Use barplotbarplot for comparing group summaries.
  • Use countplotcountplot when you want raw counts.
  • If you already aggregated your data with Pandas, consider Matplotlib bars.

Next

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

🧪 Try It Yourself

Exercise 1 – Mean by Category

Exercise 2 – Split Each Bar by Time

Exercise 3 – Change the Estimator

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did