Skip to content

Count Plots

When to use 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.

Basic countplot

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

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

Count with hue

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

Visualize it

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.

Tips

  • Use countplotcountplot when you just need frequencies, not an aggregated numeric column.
  • Pass order=order= to control category order, especially for sorted or custom sequences.
  • Combine with huehue to compare two categorical columns at once.

Next

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

🧪 Try It Yourself

Exercise 1 – Count Rows per Category

Exercise 2 – Sort by Frequency

Exercise 3 – countplot vs barplot

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did