'Drawing function for violin plots.
Draw a violin plot for each column of `vpstats`. Each filled area
extends to represent the entire data range, with optional lines at the
mean, the median, the minimum, and the maximum.
Parameters
vpstats : list of dicts
A list of dictionaries containing stats for each violin plot.
Required keys are:
- ``coords``: A list of scalars containing the coordinates that
the violin\'s kernel density estimate were evaluated at.
- ``vals``: A list of scalars containing the values of the
kernel density estimate at each of the coordinates given
in *coords*.
- ``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.
positions : array-like, default = [1, 2, ..., n]
Sets the positions of the violins. The ticks and limits are
automatically set to match the positions.
vert : bool, default = True.
If true, plots the violins veritcally.
Otherwise, plots the violins horizontally.
widths : array-like, default = 0.5
Either a scalar or a vector that sets the maximal width of
each violin. The default is 0.5, which uses about half of the
available horizontal space.
showmeans : bool, default = False
If true, will toggle rendering of the means.
showextrema : bool, default = True
If true, will toggle rendering of the extrema.
showmedians : bool, default = False
If true, will toggle rendering of the medians.
Returns
result : dict
A dictionary mapping each component of the violinplot to a
list of the corresponding collection instances created. The
dictionary has the following keys:
- ``bodies``: A list of the
:class:`matplotlib.collections.PolyCollection` instances
containing the filled area of each violin.
- ``cmeans``: A
:class:`matplotlib.collections.LineCollection` instance
created to identify the mean values of each of the
violin\'s distribution.
- ``cmins``: A
:class:`matplotlib.collections.LineCollection` instance
created to identify the bottom of each violin\'s
distribution.
- ``cmaxes``: A
:class:`matplotlib.collections.LineCollection` instance
created to identify the top of each violin\'s
distribution.
- ``cbars``: A
:class:`matplotlib.collections.LineCollection` instance
created to identify the centers of each violin\'s
distribution.
- ``cmedians``: A
:class:`matplotlib.collections.LineCollection` instance
created to identify the median values of each of the
violin\'s distribution.'

def violin(self, vpstats, positions=None, vert=True, widths=0.5, showmeans=False, showextrema=True, showmedians=False):

    means = []
    mins = []
    maxes = []
    medians = []
    artists = {}
    N = len(vpstats)
    datashape_message = u'List    of    violinplot    statistics    and    `{0}`    values    must    have    the    same    length'
    if (positions is None):
        positions = range(1, (N + 1))
    elif (len(positions) != N):
        raise ValueError(datashape_message.format(u'positions'))
    if np.isscalar(widths):
        widths = ([widths] * N)
    elif (len(widths) != N):
        raise ValueError(datashape_message.format(u'widths'))
    pmins = (((-0.25) * np.array(widths)) + positions)
    pmaxes = ((0.25 * np.array(widths)) + positions)
    if vert:
        fill = self.fill_betweenx
        perp_lines = self.hlines
        par_lines = self.vlines
    else:
        fill = self.fill_between
        perp_lines = self.vlines
        par_lines = self.hlines
    if rcParams[u'_internal.classic_mode']:
        fillcolor = u'y'
        edgecolor = u'r'
    else:
        fillcolor = edgecolor = self._get_lines.get_next_color()
    bodies = []
    for (stats, pos, width) in zip(vpstats, positions, widths):
        vals = np.array(stats[u'vals'])
        vals = (((0.5 * width) * vals) / vals.max())
        bodies += [fill(stats[u'coords'], ((- vals) + pos), (vals + pos), facecolor=fillcolor, alpha=0.3)]
        means.append(stats[u'mean'])
        mins.append(stats[u'min'])
        maxes.append(stats[u'max'])
        medians.append(stats[u'median'])
    artists[u'bodies'] = bodies
    if showmeans:
        artists[u'cmeans'] = perp_lines(means, pmins, pmaxes, colors=edgecolor)
    if showextrema:
        artists[u'cmaxes'] = perp_lines(maxes, pmins, pmaxes, colors=edgecolor)
        artists[u'cmins'] = perp_lines(mins, pmins, pmaxes, colors=edgecolor)
        artists[u'cbars'] = par_lines(positions, mins, maxes, colors=edgecolor)
    if showmedians:
        artists[u'cmedians'] = perp_lines(medians, pmins, pmaxes, colors=edgecolor)
    return artists
