📦 Seaborn Count Plot
Last Updated: 07 Nov 2025
A count plot shows how many times each category appears in a column.
Hinglish Tip 🗣: Kisi category ki frequency (kitni baar aaya) dekhni ho — count plot perfect hai.
Syntax
sns.countplot(data=df, x='category_col')
plt.show()
📘 Example Dataset
df = sns.load_dataset('tips')
df.head()
Basic Count Plot
sns.countplot(data=df, x='day')
plt.show()
Important Parameters
- data, x, y - Usually you use x for categories. y is rarely used but possible.
- hue Split categories.
sns.countplot(data=df, x='day', hue='sex')
plt.show()
- order Customize the category order.
sns.countplot(data=df, x='day', order=['Thur','Fri','Sat','Sun'])
plt.show()
- hue_order Order for hue categories.
sns.countplot(data=df, x='day', hue='sex', hue_order=['Female','Male'])
plt.show()
- palette Choose custom color theme.
sns.countplot(data=df, x='day', palette='Spectral')
plt.show()
- saturation Color intensity.
sns.countplot(data=df, x='day', saturation=0.5)
plt.show()
- legend Show/hide legend.
sns.countplot(data=df, x='day', hue='sex', legend=False)
plt.show()
- orient Vertical or horizontal orientation.
sns.countplot(data=df, y='day')
plt.show()
⭐ Full Example
sns.countplot(
data=df,
x='day',
hue='sex',
palette='coolwarm',
order=['Thur','Fri','Sat','Sun'],
hue_order=['Female','Male'],
saturation=0.7
)
plt.show()
Quick Practice
- Load penguins dataset.
- Make a countplot for species.
- Add hue for sex.
- Change palette.
- Change order manually.
|| राम नाम सत्य है ||
