Draw a patch representing a KDE and add observations or box plot statistics.
A violin plot plays a similar role as a box-and-whisker plot. It shows the
distribution of data points after grouping by one (or more) variables.
Unlike a box plot, each violin is drawn using a kernel density estimate
of the underlying distribution.
data : DataFrame, Series, dict, array, or list of arrays
Dataset for plotting. If x and y are absent, this is
interpreted as wide-form. Otherwise it is expected to be long-form.
x, y, hue : names of variables in data or vector data
Inputs for plotting long-form data. See examples for interpretation.
order, hue_order : lists of strings
Order to plot the categorical levels in; otherwise the levels are
inferred from the data objects.
orient : “v” | “h” | “x” | “y”
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.
color : matplotlib color
Single color for the elements in the plot.
palette : palette name, list, or dict
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.
saturation : float
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.
fill : bool
If True, use a solid patch. Otherwise, draw as line art.
inner : {“box”, “quart”, “point”, “stick”, None}
Representation of the data in the violin interior. One of the following:
"box": draw a miniature box-and-whisker plot
"quart": show the quartiles of the data
"point" or "stick": show each observation
split : bool
Show an un-mirrored distribution, alternating sides when using hue.
width : float
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.
dodge : “auto” or bool
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.
gap : float
Shrink on the orient axis by this factor to add a gap between dodged elements.
linewidth : float
Width of the lines that frame the plot elements.
linecolor : color
Color to use for line elements, when fill is True.
cut : float
Distance, in units of bandwidth, to extend the density past extreme
datapoints. Set to 0 to limit the violin within the data range.
gridsize : int
Number of points in the discrete grid used to evaluate the KDE.
bw_method : {“scott”, “silverman”, float}
Either the name of a reference rule or the scale factor to use when
computing the kernel bandwidth. The actual kernel size will be
determined by multiplying the scale factor by the standard deviation of
the data within each group.
bw_adjust: float
Factor that scales the bandwidth to use more or less smoothing.
density_norm : {“area”, “count”, “width”}
Method that normalizes each density to determine the violin’s width.
If area, each violin will have the same area. If count, the width
will be proportional to the number of observations. If width, each
violin will have the same width.
common_norm : bool
When True, normalize the density across all violins.
Normalization in data units for colormap applied to the hue
variable when it is numeric. Not relevant if hue is categorical.
formatter : callable
Function for converting categorical data into strings. Affects both grouping
and tick labels.
log_scale : bool or number, or pair of bools or numbers
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.
native_scale : bool
When True, numeric or datetime values on the categorical axis will maintain
their original scaling rather than being converted to fixed indices.
legend : “auto”, “brief”, “full”, or False
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.
scale : {“area”, “count”, “width”}
scale_hue : bool
bw : {‘scott’, ‘silverman’, float}
inner_kws : dict of key, value mappings
Keyword arguments for the “inner” plot, passed to one of:
Returns the Axes object with the plot drawn onto it.
Examples
The default violinplot represents a distribution two ways: a patch showing a symmetric kernel density estimate (KDE), and the quartiles / whiskers of a box plot:
By default, the violins are drawn at fixed positions on a categorical scale, even if the grouping variable is numeric. Starting in version 0.13.0, pass the native_scale=True parameter to preserve the original scale on both axes: