Lecture

Categorical Plots (barplot, countplot)

Categorical plots allow you to visualize how data is distributed across categories — such as weekdays, product types, or survey answers.

In Seaborn, two of the most commonly used categorical plots are:

  • barplot() – Displays the average value of a numeric variable for each category.
  • countplot() – Displays how often each category occurs in the dataset.

Bar Plot

A bar plot is ideal for comparing average values across different categories. By default, Seaborn’s barplot() computes the mean of the numeric variable for each group.

Average Total Bill by Day
import seaborn as sns import matplotlib.pyplot as plt tips = sns.load_dataset("tips") sns.barplot(data=tips, x="day", y="total_bill") plt.title("Average Total Bill by Day") plt.show()

Count Plot

A count plot is best for showing how frequently each category appears in the dataset. Unlike a bar plot, countplot() doesn’t need a numeric column — it automatically counts the number of records in each category.

Count of Records by Day
sns.countplot(data=tips, x="day") plt.title("Count of Records by Day") plt.show()

Choosing the Right Plot

  • Use barplot() to compare average values or other aggregations across categories.
  • Use countplot() to display frequency counts or category distributions.
Quiz
0 / 1

A bar plot in Seaborn is used to show the number of occurrences in each category.

True
False

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help