Categorical Plots (barplot, countplot)
Categorical plots help you visualize data that is grouped by categories, such as days of the week, product types, or survey responses.
In Seaborn, two of the most common categorical plot functions are:
barplot()
– Shows the average value of a numeric variable for each category.countplot()
– Shows the number of occurrences in each category.
Bar Plot
A bar plot is useful when you want to compare average values across categories.
By default, Seaborn’s barplot()
calculates the mean for each category.
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 useful when you want to see how many times each category appears in your dataset.
Instead of using a numeric y-value, countplot()
counts the rows.
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()
when you want to compare averages or aggregated values. - Use
countplot()
when you want to see frequency counts of categories.
What’s Next?
Next, you’ll open a Jupyter notebook to try both plot types and experiment with different datasets.
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