matplotlib.axes.Axes.violin#
- Axes.violin(vpstats,positions=None,*,vert=None,orientation='vertical',widths=0.5,showmeans=False,showextrema=True,showmedians=False,side='both',facecolor=None,linecolor=None)[source]#
Draw a violin plot from pre-computed statistics.
Draw a violin plot for each column ofvpstats. Each filled areaextends to represent the entire data range, with optional lines at themean, the median, the minimum, the maximum, and the quantiles values.
- Parameters:
- vpstatslist of dicts
A list of dictionaries containing stats for each violin plot.Required keys are:
coords: A list of scalars containing the coordinates thatthe violin's kernel density estimate were evaluated at.vals: A list of scalars containing the values of thekernel density estimate at each of the coordinates givenincoords.mean: The mean value for this violin's dataset.median: The median value for this violin's dataset.min: The minimum value for this violin's dataset.max: The maximum value for this violin's dataset.
Optional keys are:
quantiles: A list of scalars containing the quantile valuesfor this violin's dataset.
- 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 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.
- 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.
For backward compatibility, iffacecolor is not given, the bodywill get an Artist-level transparency
alphaof 0.3, which will persist if you afterwards change the facecolor,e.g. viaresult['bodies'][0].set_facecolor('red').Iffacecolor is given, there is no Artist-level transparency.To set transparency forfacecolor oredgecolor use(color,alpha)tuples.- 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.
- 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 thePolyCollectioninstances containing the filled area of each violin.cmeans: ALineCollectioninstance that marksthe mean values of each of the violin's distribution.cmins: ALineCollectioninstance that marksthe bottom of each violin's distribution.cmaxes: ALineCollectioninstance that marksthe top of each violin's distribution.cbars: ALineCollectioninstance that marksthe centers of each violin's distribution.cmedians: ALineCollectioninstance thatmarks the median values of each of the violin's distribution.cquantiles: ALineCollectioninstance createdto identify the quantiles values of each of the violin'sdistribution.
See also
violinplotDraw a violin plot from data instead of pre-computed statistics.
cbook.violin_statsCalculate avpstats dictionary from data, suitable for passing to violin.