seaborn.boxplot
- seaborn.boxplot(data=None, *, x=None, y=None, hue=None, order=None, hue_order=None, orient=None, color=None, palette=None, , , , , , , , , , , , , , , ,
Draw a box plot to show distributions with respect to categories.
A box plot (or box-and-whisker 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 inter-quartile range.
See the tutorial for more information.
Dataset for plotting. If x and y are absent, this is
interpreted as wide-form. Otherwise it is expected to be long-form.
data or vector dataInputs for plotting long-form data. See examples for interpretation.
Order to plot the categorical levels in; otherwise the levels are inferred from the data objects.
Orientation of the plot (vertical or horizontal). This is usually
inferred based on the type of the input variables, but it can be used
to resolve ambiguity when both x and y are numeric or when
plotting wide-form data.
Single color for the elements in the plot.
Colors to use for the different levels of the hue variable. Should
be something that can be interpreted by color_palette(), or a
dictionary mapping hue levels to matplotlib colors.
Proportion of the original saturation to draw fill colors in. Large
patches often look better with desaturated colors, but set this to
1 if you want the colors to perfectly match the input values.
If True, use a solid patch. Otherwise, draw as line art.
When hue mapping is used, whether elements should be narrowed and shifted along
the orient axis to eliminate overlap. If "auto", set to True when the
orient variable is crossed with the categorical variable or False otherwise.
Width allotted to each element on the orient axis. When native_scale=True,
it is relative to the minimum distance between two values in the native scale.
Shrink on the orient axis by this factor to add a gap between dodged elements.
Paramater that controls whisker length. If scalar, whiskers are drawn to the farthest datapoint within whis * IQR from the nearest hinge. If a tuple, it is interpreted as percentiles that whiskers represent.
Color to use for line elements, when fill is True.
Width of the lines that frame the plot elements.
Size of the markers used to indicate outlier observations.
matplotlib.colors.Normalize objectNormalization in data units for colormap applied to the hue
variable when it is numeric. Not relevant if hue is categorical.
Set axis scale(s) to log. A single value sets the data axis for any numeric
axes in the plot. A pair of values sets each axis independently.
Numeric values are interpreted as the desired base (default 10).
When None or False, seaborn defers to the existing Axes scale.
When True, numeric or datetime values on the categorical axis will maintain their original scaling rather than being converted to fixed indices.
Function for converting categorical data into strings. Affects both grouping and tick labels.
How to draw the legend. If “brief”, numeric hue and size
variables will be represented with a sample of evenly spaced values.
If “full”, every group will get an entry in the legend. If “auto”,
choose between brief or full representation based on number of levels.
If False, no legend data is added and no legend is drawn.
Axes object to draw the plot onto, otherwise uses the current Axes.
Other keyword arguments are passed through to
matplotlib.axes.Axes.boxplot().
Returns the Axes object with the plot drawn onto it.
Draw a single horizontal boxplot, assigning the data directly to the coordinate variable:
sns.boxplot(x=titanic["age"])
Group by a categorical variable, referencing columns in a dataframe:
sns.boxplot(data=titanic, x="age", y="class")
Draw a vertical boxplot with nested grouping by two variables:
sns.boxplot(data=titanic, x="class", y="age", hue="alive")
Draw the boxes as line art and add a small gap between them:
sns.boxplot(data=titanic, x="class", y="age", hue="alive", fill=False, gap=.1)
Cover the full range of the data with the whiskers:
sns.boxplot(data=titanic, x="age", y="deck", whis=(0, 100))
Draw narrower boxes:
sns.boxplot(data=titanic, x="age", y="deck", width=.5)
Modify the color and width of all the line artists:
sns.boxplot(data=titanic, x="age", y="deck", color=".8", linecolor="#137", linewidth=.75)
Group by a numeric variable and preserve its native scaling:
ax = sns.boxplot(x=titanic["age"].round(-1), y=titanic["fare"], native_scale=True)
ax.axvline(25, color=".3", dashes=(2
Customize the plot using parameters of the underlying matplotlib function:
sns.boxplot(
data=titanic, x="age", y="class",
notch=True, showcaps=False,
flierprops={"marker": "x"},
boxprops={"facecolor": (.3, .5,
Combine a categorical plot with a FacetGrid.