Bar plots
Seaborn basics
2 min read
This section is 2 min read, full guide is 42 min read
Published Oct 7 2025, updated Aug 17 2026
24
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation
seaborn.barplot() is used to visualise the mean (or another aggregate) of a numerical variable for different categories.
It automatically computes and plots:
- The central tendency (by default, the mean) of each category
- Error bars showing uncertainty (by default, the 95% confidence interval)
In other words:
Each bar shows the average of
yfor each category ofx.
Syntax:
sns.barplot( data=None, x=None, y=None, hue=None, estimator='mean', ci='auto', palette=None, order=None, hue_order=None, orient=None, errorbar=('ci', 95), width=0.8, dodge=True, **kwargs)Parameters:
data= DataFrame with datax,y= Variables for categories (x) and values (y)hue= Adds subcategories (grouped bars)estimator= Function for aggregation (default = mean)ci/errorbar= Confidence interval or error bars (None, 'sd', 'ci', or numeric)palette= Colour paletteorder/hue_order= Specify order of categoriesorient= "v" (vertical) or "h" (horizontal)width= Bar widthdodge= Separate bars for hue categories (True/False)
Basic example
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot(data=tips, x="day", y="total_bill")plt.show()This shows the average total bill for each day of the week.

Add hue (subgroups)
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot(data=tips, x="day", y="total_bill", hue="sex")plt.show()- Each day shows two bars, one for each sex.
- Bars are placed side by side (because
dodge=Trueby default).

Change estimator (aggregation function)
import seaborn as snsimport matplotlib.pyplot as pltimport numpy as nptips = sns.load_dataset("tips")sns.barplot(data=tips, x="day", y="total_bill", estimator=np.median)plt.show()Now, each bar shows the median total bill per day instead of the mean.

Customise error bars
Remove error bars:
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot(data=tips, x="day", y="total_bill", ci=None)plt.show()
Or show standard deviation:
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot(data=tips, x="day", y="total_bill", errorbar='sd')plt.show()
Horizontal bars
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot(data=tips, x="total_bill", y="day", orient="h")plt.show()Simply swap x and y and set orient="h" to flip orientation.

Customise colours and style
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot( data=tips, x="day", y="total_bill", hue="sex", palette="coolwarm", edgecolor="black", width=0.7)plt.show()palette="coolwarm"→ colourful gradientedgecolor="black"→ outline barswidth=0.7→ slightly thinner bars

Control category order
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot( data=tips, x="day", y="total_bill", order=["Sun", "Sat", "Fri", "Thur"])plt.show()Controls the order of categories on the x-axis.

Combine with hue and estimator
import seaborn as snsimport matplotlib.pyplot as plttips = sns.load_dataset("tips")sns.barplot( data=tips, x="day", y="tip", hue="smoker", estimator=sum, palette="pastel")plt.show()Bars now show the total tips (not average) by day and smoker status.
