Categorical Plots (barplot, countplot)
Categorical plots help you visualize data grouped by categories, such as days of the week, product types, or survey responses.
In Seaborn, two commonly used functions for categorical data are:
barplot()
: Shows the average value of a numeric variable for each category.countplot()
: Shows how many times each category appears.
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 the dataset.
Unlike a bar plot, countplot()
does not require a numeric y-value because it counts the rows automatically.
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 other aggregated values. - Use
countplot()
when you want to see frequency counts of each category.
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