Category-level summaries
Compare a numeric measurement across categories.
Seaborn · Function
Show aggregate estimates for numeric data as rectangular bars, with optional uncertainty intervals. By default, barplot displays group means with 95% confidence intervals.
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.
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)| Name | Type | Description |
|---|---|---|
data | DataFrame, Series, dict, array, or list of arrays | Dataset for plotting; may be a DataFrame, Series, dictionary, array, or list of arrays. |
x | vector or key in data | Input variable for the horizontal axis or categorical grouping. |
y | vector or key in data | Input variable for the vertical axis or numeric measurement. |
hue | vector or key in data | Semantic variable that creates subgroups and color distinctions. |
estimator | string or callable | Function or callable used to obtain the point estimate. |
errorbar | string, tuple, callable, or None | Method and level used to compute the uncertainty interval. |
n_boot | int | Number of bootstrap iterations used for confidence intervals. |
seed | int, numpy.random.Generator, or None | Seed controlling the random number generator for uncertainty calculations. |
ax | matplotlib.axes.Axes or None | Matplotlib Axes containing the completed plot. |
matplotlib.axes.Axes
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.
Compare a numeric measurement across categories.
Show subgroup differences within each category.
Communicate uncertainty alongside aggregate estimates.
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".
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.
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.
catplotpointplotcountplotstripplotswarmplot