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

Seaborn · Function

boxplot

Draws box-and-whisker plots that compare quantitative distributions across categorical levels. Quartiles form the box, whiskers follow the configured whis rule, and outlying observations are shown separately.

Since
0.13.0

How it works

Call boxplot with a dataset and categorical and numeric variables to compare distributions. It draws quartile-based boxes, extends whiskers according to the whis rule, and marks observations outside that rule as fliers; optional hue, ordering, orientation, scaling, and styling arguments refine the display.

Syntax

seaborn.boxplot(*data=None, *, x=None, y=None, hue=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, fill=True, dodge='auto', width=0.8, gap=0, whis=1.5, linecolor='auto', linewidth=None, fliersize=None, hue_norm=None, native_scale=False, log_scale=None, formatter=None, legend='auto', ax=None, **kwargs)

Parameters

NameTypeDescription
dataDataFrame, Series, dict, array, or list of arraysDataset for plotting.
xvector or key in dataInput data for the x axis.
yvector or key in dataInput data for the y axis.
huevector or key in dataSemantic variable that is mapped to determine the color of plot elements.
orderlist of stringsOrder to plot the categorical levels in.
hue_orderlist of stringsSpecific order for the appearance of the hue levels.
orient“v” | “h” | “x” | “y”Orientation of the plot.
colormatplotlib colorColor for all of the elements.
palettepalette name, list, or dictColors to use for the different levels of the hue variable.
saturationfloatProportion of the original saturation to draw colors at.
fillboolWhether the boxes should be drawn with a solid fill.
dodgebool or “auto”When hue nesting is used, whether the elements should be shifted along the categorical axis.

Returns

matplotlib.axes.Axes

Key points

  • Use boxplot when comparing a quantitative distribution across categorical levels.
  • The central box summarizes the lower quartile, median, and upper quartile.
  • Observations beyond the whisker criterion appear separately as outliers.
  • The data argument accepts common tabular or array-like dataset forms.
  • Pass vectors directly to the semantic variables when a separate dataset object is unnecessary.
  • Set native_scale=True to avoid ordinal repositioning when category values have a meaningful native scale.

Common mistakes

  • Whiskers do not necessarily reach the minimum and maximum values; their extent is controlled by the outlier rule.
  • Categorical positions use ordinal spacing by default; set native_scale=True when the categorical variable's numeric or datetime scale should be preserved.

Example: Grouped boxplot

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")
sns.boxplot(data=tips, x="day", y="total_bill", hue="smoker")
plt.show()

This groups numeric bill totals by day and adds smoker as a nested categorical grouping.

When to use it

Categorical distribution comparison

Compare a numeric measurement across named categories such as days, groups, or classes.

Nested subgroup analysis

Add hue to compare subgroups within each primary category.

Distribution diagnostics

Inspect spread and potential outliers before choosing a statistical summary.

Interview questions

QWhat information does a Seaborn boxplot encode?

boxplot visualizes quantitative distributions across categories. The box represents quartiles, while whiskers show the non-outlier range and points beyond the configured rule are treated as outliers.

Follow-up: How would you show every observation instead of only the box-plot summary? Add a point-based categorical plot such as stripplot alongside the boxplot.

QHow do you create grouped boxplots?

Use x and y to assign variables, and hue to create an additional categorical subdivision. With a long-form DataFrame, these variable names select columns; with wide-form data, numeric columns can be plotted directly.

Follow-up: How can category order be made deterministic? Pass an explicit order, and use hue_order for the hue levels.

QHow does whis affect the plotted result?

The default whis=1.5 makes the whisker rule a function of the interquartile range. You can instead pass another value or a pair of percentile bounds to change which observations are treated as outliers.

Follow-up: How can the display preserve actual numeric spacing for a categorical-looking axis? Enable native_scale=True, which was added for this behavior in version 0.13.0.

  • boxenplot
  • stripplot
  • swarmplot
  • violinplot
  • catplot

Source: seaborn.boxplot. Checked 2026-10-15.