Bar plots

Seaborn basics

2 min read

Published Oct 7 2025


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 sns
import 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 sns
import 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 sns
import matplotlib.pyplot as plt
import 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 sns
import 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 sns
import 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 sns
import 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 sns
import 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 sns
import 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 sns
import 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

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact