Skip to content

Count Plots

Count plots answer:

  • How many records are in each category?
  • Is there imbalance?

Examples:

  • Orders by status
  • Users by plan
  • Tickets by priority
diagram How countplot works mermaid
countplot tallies rows per category automatically — no separate aggregation step needed.
countplot
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(6, 4))
sns.countplot(data=tips, x="day")
plt.title("Count by day")
plt.tight_layout()
plt.show()
Sorted categories
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
order = tips["day"].value_counts().index
 
plt.figure(figsize=(6, 4))
sns.countplot(data=tips, x="day", order=order)
plt.title("Count by day (sorted)")
plt.tight_layout()
plt.show()
Countplot with hue
import seaborn as sns
import matplotlib.pyplot as plt
 
tips = sns.load_dataset("tips")
 
plt.figure(figsize=(7, 4))
sns.countplot(data=tips, x="day", hue="sex")
plt.title("Count by day split by sex")
plt.tight_layout()
plt.show()

Each bar’s height is simply “how many rows had this category” — nothing is averaged:

sketch Category counts as bars p5.js
Bar height is a raw tally of rows per category, unlike barplot which averages a numeric column.
  • Use countplot when you just need frequencies, not an aggregated numeric column.
  • Pass order= to control category order, especially for sorted or custom sequences.
  • Combine with hue to compare two categorical columns at once.

Continue to Heatmaps for Correlation to visualize relationships between several numeric columns at once.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading