Bar plots

Seaborn basics

2 min read

Published Oct 7 2025, updated Aug 17 2026


24
0
0
0

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 y for each category of x.


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 data
  • x, 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 palette
  • order / hue_order = Specify order of categories
  • orient = "v" (vertical) or "h" (horizontal)
  • width = Bar width
  • dodge = Separate bars for hue categories (True/False)




Basic example

import seaborn as snsimport matplotlib.pyplot as plt​tips = 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.


seaborn bar plot basic example





Add hue (subgroups)

import seaborn as snsimport matplotlib.pyplot as plt​tips = 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=True by default).

seaborn bar plot hue example





Change estimator (aggregation function)

import seaborn as snsimport matplotlib.pyplot as pltimport numpy as np​tips = 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.


seaborn bar plot change estimator example





Customise error bars

Remove error bars:

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.barplot(data=tips, x="day", y="total_bill", ci=None)plt.show()

seaborn bar plot no error bars example

Or show standard deviation:

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.barplot(data=tips, x="day", y="total_bill", errorbar='sd')plt.show()

seaborn bar plot std example





Horizontal bars

import seaborn as snsimport matplotlib.pyplot as plt​tips = 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.


seaborn bar plot horizontal example





Customise colours and style

import seaborn as snsimport matplotlib.pyplot as plt​tips = 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 gradient
  • edgecolor="black" → outline bars
  • width=0.7 → slightly thinner bars

seaborn bar plot colours style example





Control category order

import seaborn as snsimport matplotlib.pyplot as plt​tips = 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.


seaborn bar plot order example





Combine with hue and estimator

import seaborn as snsimport matplotlib.pyplot as plt​tips = 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.


seaborn bar plot hue estimator example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact