matplotlib.pyplot.violinplot#
- matplotlib.pyplot.violinplot(dataset,positions=None,*,vert=None,orientation='vertical',widths=0.5,showmeans=False,showextrema=True,showmedians=False,quantiles=None,points=100,bw_method=None,side='both',facecolor=None,linecolor=None,data=None)[source]#
Make a violin plot.
Make a violin plot for each column ofdataset or each vector insequencedataset. Each filled area extends to represent theentire data range, with optional lines at the mean, the median,the minimum, the maximum, and user-specified quantiles.
- Parameters:
- datasetArray or a sequence of vectors.
The input data.
- positionsarray-like, default: [1, 2, ..., n]
The positions of the violins; i.e. coordinates on the x-axis forvertical violins (or y-axis for horizontal violins).
- vertbool, optional
Deprecated since version 3.10:Useorientation instead.
If this is given during the deprecation period, it overridestheorientation parameter.
If True, plots the violins vertically.If False, plots the violins horizontally.
- orientation{'vertical', 'horizontal'}, default: 'vertical'
If 'horizontal', plots the violins horizontally.Otherwise, plots the violins vertically.
Added in version 3.10.
- widthsfloat or array-like, default: 0.5
The maximum width of each violin in units of thepositions axis.The default is 0.5, which is half the available space when using defaultpositions.
- showmeansbool, default: False
Whether to show the mean with a line.
- showextremabool, default: True
Whether to show extrema with a line.
- showmediansbool, default: False
Whether to show the median with a line.
- quantilesarray-like, default: None
If not None, set a list of floats in interval [0, 1] for each violin,which stands for the quantiles that will be rendered for thatviolin.
- pointsint, default: 100
The number of points to evaluate each of the gaussian kernel densityestimations at.
- bw_method{'scott', 'silverman'} or float or callable, default: 'scott'
The method used to calculate the estimator bandwidth. If afloat, this will be used directly as
kde.factor
. If acallable, it should take amatplotlib.mlab.GaussianKDE
instance asits only parameter and return a float.- side{'both', 'low', 'high'}, default: 'both'
'both' plots standard violins. 'low'/'high' onlyplots the side below/above the positions value.
- facecolorcolor or list ofcolor, optional
If provided, will set the face color(s) of the violins.
Added in version 3.11.
- linecolorcolor or list ofcolor, optional
If provided, will set the line color(s) of the violins (thehorizontal and vertical spines and body edges).
Added in version 3.11.
- dataindexable object, optional
If given, the following parameters also accept a string
s
, which isinterpreted asdata[s]
ifs
is a key indata
:dataset
- Returns:
- dict
A dictionary mapping each component of the violinplot to alist of the corresponding collection instances created. Thedictionary has the following keys:
bodies
: A list of thePolyCollection
instances containing the filled area of each violin.cmeans
: ALineCollection
instance that marksthe mean values of each of the violin's distribution.cmins
: ALineCollection
instance that marksthe bottom of each violin's distribution.cmaxes
: ALineCollection
instance that marksthe top of each violin's distribution.cbars
: ALineCollection
instance that marksthe centers of each violin's distribution.cmedians
: ALineCollection
instance thatmarks the median values of each of the violin's distribution.cquantiles
: ALineCollection
instance createdto identify the quantile values of each of the violin'sdistribution.
See also
Axes.violin
Draw a violin from pre-computed statistics.
boxplot
Draw a box and whisker plot.
Notes
Note
This is thepyplot wrapper for
axes.Axes.violinplot
.