📊 Seaborn Bar Plot
Last Updated: 07 Nov 2025
A bar plot shows the average value of a numerical column for each category.
Hinglish Tip 🗣: Category ke hisaab se average compare karna ho (jaise day-wise average bill), bar plot best.
Basic Syntax
sns.barplot(data=df, x='category_col', y='numeric_col')
plt.show()
📘 Example Dataset
df = sns.load_dataset('tips')
df.head()
📊 Basic Bar Plot
sns.barplot(data=df, x='day', y='total_bill')
plt.show()
Important Parameters
data,x,yDataset and columns to visualize.hueSplit each bar by category.
sns.barplot(data=df, x='day', y='total_bill', hue='sex')
plt.show()
estimatorBy default, Seaborn uses mean. You can change it tosum,count, etc.
from numpy import median
sns.barplot(data=df, x='day', y='total_bill', estimator=median)
plt.show()
ci(Confidence Interval) Remove the vertical error bars.
sns.barplot(data=df, x='day', y='total_bill', ci=None)
plt.show()
paletteCustom color theme.
sns.barplot(data=df, x='day', y='total_bill', palette='magma')
plt.show()
orderControl category order.
sns.barplot(data=df, x='day', y='total_bill', order=['Thur', 'Fri', 'Sat', 'Sun'])
plt.show()
hue_orderCustom order for hue.
sns.barplot(data=df, x='day', y='total_bill', hue='sex', hue_order=['Male', 'Female'])
plt.show()
saturationBar color intensity.
sns.barplot(data=df, x='day', y='total_bill', saturation=0.4)
plt.show()
errorbarControl error bar style (new Seaborn versions).
sns.barplot(data=df, x='day', y='total_bill', errorbar=('ci', 95))
plt.show()
⭐ Full Example
sns.barplot(
data=df,
x='day',
y='total_bill',
hue='sex',
estimator=sum,
ci=None,
palette='coolwarm',
saturation=0.8,
order=['Thur','Fri','Sat','Sun'],
hue_order=['Female','Male']
)
plt.show()
Quick Practice
- Use
penguinsdataset. - Make a barplot of
speciesvsbody_mass_g. - Add a hue for
sex. - Change estimator to
median. - Remove CI.