seaborn.
boxplot
(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, fliersize=5, linewidth=None, whis=1.5, notch=False, ax=None, **kwargs)¶Draw a box plot to show distributions with respect to categories.
A box plot (or boxandwhisker plot) shows the distribution of quantitative data in a way that facilitates comparisons between variables or across levels of a categorical variable. The box shows the quartiles of the dataset while the whiskers extend to show the rest of the distribution, except for points that are determined to be “outliers” using a method that is a function of the interquartile range.
Input data can be passed in a variety of formats, including:
x
, y
, and/or hue
parameters.x
, y
, and hue
variables will determine how the data are plotted.plt.boxplot
(e.g. a 2d array or list of vectors)In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.
Parameters:  x, y, hue : names of variables in
data : DataFrame, array, or list of arrays, optional
order, hue_order : lists of strings, optional
orient : “v”  “h”, optional
color : matplotlib color, optional
palette : seaborn color palette or dict, optional
saturation : float, optional
width : float, optional
fliersize : float, optional
linewidth : float, optional
whis : float, optional
notch : boolean, optional
ax : matplotlib Axes, optional
kwargs : key, value mappings


Returns:  ax : matplotlib Axes

See also
violinplot
stripplot
swarmplot
Examples
Draw a single horizontal boxplot:
>>> import seaborn as sns
>>> sns.set_style("whitegrid")
>>> tips = sns.load_dataset("tips")
>>> ax = sns.boxplot(x=tips["total_bill"])
Draw a vertical boxplot grouped by a categorical variable:
>>> ax = sns.boxplot(x="day", y="total_bill", data=tips)
Draw a boxplot with nested grouping by two categorical variables:
>>> ax = sns.boxplot(x="day", y="total_bill", hue="smoker",
... data=tips, palette="Set3")
Draw a boxplot with nested grouping when some bins are empty:
>>> ax = sns.boxplot(x="day", y="total_bill", hue="time",
... data=tips, linewidth=2.5)
Control box order by passing an explicit order:
>>> ax = sns.boxplot(x="time", y="tip", data=tips,
... order=["Dinner", "Lunch"])
Draw a boxplot for each numeric variable in a DataFrame:
>>> iris = sns.load_dataset("iris")
>>> ax = sns.boxplot(data=iris, orient="h", palette="Set2")
Use swarmplot()
to show the datapoints on top of the boxes:
>>> ax = sns.boxplot(x="day", y="total_bill", data=tips)
>>> ax = sns.swarmplot(x="day", y="total_bill", data=tips, color=".25")
Draw a box plot on to a FacetGrid
to group within an additional
categorical variable:
>>> g = sns.FacetGrid(tips, col="time", size=4, aspect=.7)
>>> (g.map(sns.boxplot, "sex", "total_bill", "smoker")
... .despine(left=True)
... .add_legend(title="smoker"))
<seaborn.axisgrid.FacetGrid object at 0x...>