Skip to main content
Albero Academy

Bar & Count Plots

Aggregate a value per category, or count rows per category.

Categorical Plots9 min

Two closely-related charts: barplot shows an aggregate (mean by default) of a numeric value per category, and countplot shows the count of rows per category. Both add error bars and grouping for free.

barplot — aggregate a value

mean per category with CI
sns.barplot(data=tips, x="day", y="total_bill") # mean bill per day + CI
sns.barplot(data=tips, x="day", y="total_bill", hue="sex") # grouped bars
sns.barplot(data=tips, x="day", y="total_bill", estimator="median", errorbar=None)

countplot — count rows

frequency per category
sns.countplot(data=tips, x="day") # how many rows per day
sns.countplot(data=tips, x="day", hue="sex") # grouped counts

Key takeaways

  1. 01barplot shows an aggregate (mean by default) of a value per category, with a CI.
  2. 02countplot shows the number of rows per category (no y).
  3. 03estimator changes the aggregation (median, sum…); errorbar controls the interval.
  4. 04hue groups both into side-by-side bars.

Finished this chapter?

Mark it complete to track your progress through Seaborn.