📦 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.
Basic 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.hueSplit categories.
sns.countplot(data=df, x='day', hue='sex')
plt.show()
orderCustomize the category order.
sns.countplot(data=df, x='day', order=['Thur','Fri','Sat','Sun'])
plt.show()
hue_orderOrder for hue categories.
sns.countplot(data=df, x='day', hue='sex', hue_order=['Female','Male'])
plt.show()
paletteChoose custom color theme.
sns.countplot(data=df, x='day', palette='Spectral')
plt.show()
saturationColor intensity.
sns.countplot(data=df, x='day', saturation=0.5)
plt.show()
legendShow/hide legend.
sns.countplot(data=df, x='day', hue='sex', legend=False)
plt.show()
orientVertical 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
penguinsdataset. - Make a countplot for
species. - Add hue for
sex. - Change palette.
- Change order manually.
|| राम नाम सत्य है ||