Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Seaborn · Function

barplot

Show aggregate estimates for numeric data as rectangular bars, with optional uncertainty intervals. By default, barplot displays group means with 95% confidence intervals.

How it works

barplot groups observations by the categorical variables and computes an estimate for the numeric variable, using the mean by default. It draws each estimate as a rectangular bar and can add uncertainty intervals or other error representations; the function returns the matplotlib Axes containing the plot.

Syntax

seaborn.barplot(data=None, *, x=None, y=None, hue=None, order=None, hue_order=None, estimator='mean', errorbar=('ci', 95), n_boot=1000, seed=None, units=None, weights=None, orient=None, color=None, palette=None, saturation=0.75, fill=True, hue_norm=None, width=0.8, dodge='auto', gap=0, log_scale=None, native_scale=False, formatter=None, legend='auto', capsize=0, err_kws=None, ci=<deprecated>, errcolor=<deprecated>, errwidth=<deprecated>, ax=None, **kwargs)

Parameters

NameTypeDescription
dataDataFrame, Series, dict, array, or list of arraysDataset for plotting; may be a DataFrame, Series, dictionary, array, or list of arrays.
xvector or key in dataInput variable for the horizontal axis or categorical grouping.
yvector or key in dataInput variable for the vertical axis or numeric measurement.
huevector or key in dataSemantic variable that creates subgroups and color distinctions.
estimatorstring or callableFunction or callable used to obtain the point estimate.
errorbarstring, tuple, callable, or NoneMethod and level used to compute the uncertainty interval.
n_bootintNumber of bootstrap iterations used for confidence intervals.
seedint, numpy.random.Generator, or NoneSeed controlling the random number generator for uncertainty calculations.
axmatplotlib.axes.Axes or NoneMatplotlib Axes containing the completed plot.

Returns

matplotlib.axes.Axes

Key points

  • Each bar communicates a point estimate, while an associated error bar communicates uncertainty.
  • The plotted height or horizontal extent summarizes a numeric variable after aggregation.
  • With vertical orientation, the estimate determines each rectangle's height.
  • Uncertainty is encoded separately from the estimate through an error bar.
  • The current default errorbar setting is a 95% confidence interval.
  • The default bootstrap count for uncertainty estimation is 1,000 iterations.

Example: Grouped bar plot

import seaborn as sns
import matplotlib.pyplot as plt

penguins = sns.load_dataset("penguins")
sns.barplot(
    data=penguins,
    x="species",
    y="body_mass_g",
    hue="sex",
    errorbar="sd",
)
plt.show()

This groups penguin body masses by species and sex, displaying the mean for each group with standard-deviation error bars.

When to use it

Category-level summaries

Compare a numeric measurement across categories.

Grouped comparisons

Show subgroup differences within each category.

Estimate with uncertainty

Communicate uncertainty alongside aggregate estimates.

Interview questions

QWhat does seaborn.barplot visualize?

barplot aggregates a numeric variable within categorical groups and represents the resulting estimate with rectangular bars. The default estimator is the mean, and uncertainty is shown with error bars.

Follow-up: How would you display variability rather than a confidence interval? Pass an errorbar option such as "sd".

QHow are data and categories specified?

The function accepts long-form data through data and maps columns with x, y, and optionally hue. It can also receive vectors directly, while order and hue_order control category ordering.

Follow-up: How can you make category order deterministic? Supply order and, when applicable, hue_order explicitly.

QHow does barplot compute and configure uncertainty?

errorbar controls the uncertainty representation, with the current default being a 95% confidence interval. n_boot sets the number of bootstrap iterations, and seed controls reproducibility.

Follow-up: What is the practical trade-off of increasing n_boot? It can make the interval estimate more stable but increases computation time.

  • catplot
  • pointplot
  • countplot
  • stripplot
  • swarmplot

Source: seaborn.barplot — seaborn 0.13.2 documentation. Checked 2026-10-15.