'Drawing function for box and whisker plots.
Make a box and whisker plot for each column of *x* or each
vector in sequence *x*.  The box extends from the lower to
upper quartile values of the data, with a line at the median.
The whiskers extend from the box to show the range of the
data.  Flier points are those past the end of the whiskers.
Parameters
bxpstats : list of dicts
A list of dictionaries containing stats for each boxplot.
Required keys are:
- ``med``: The median (scalar float).
- ``q1``: The first quartile (25th percentile) (scalar
float).
- ``q3``: The third quartile (75th percentile) (scalar
float).
- ``whislo``: Lower bound of the lower whisker (scalar
float).
- ``whishi``: Upper bound of the upper whisker (scalar
float).
Optional keys are:
- ``mean``: The mean (scalar float). Needed if
``showmeans=True``.
- ``fliers``: Data beyond the whiskers (sequence of floats).
Needed if ``showfliers=True``.
- ``cilo`` & ``cihi``: Lower and upper confidence intervals
about the median. Needed if ``shownotches=True``.
- ``label``: Name of the dataset (string). If available,
this will be used a tick label for the boxplot
positions : array-like, default = [1, 2, ..., n]
Sets the positions of the boxes. The ticks and limits
are automatically set to match the positions.
widths : array-like, default = None
Either a scalar or a vector and sets the width of each
box. The default is ``0.15*(distance between extreme
positions)``, clipped to no less than 0.15 and no more than
0.5.
vert : bool, default = False
If `True` (default), makes the boxes vertical.  If `False`,
makes horizontal boxes.
patch_artist : bool, default = False
If `False` produces boxes with the
`~matplotlib.lines.Line2D` artist.  If `True` produces boxes
with the `~matplotlib.patches.Patch` artist.
shownotches : bool, default = False
If `False` (default), produces a rectangular box plot.
If `True`, will produce a notched box plot
showmeans : bool, default = False
If `True`, will toggle on the rendering of the means
showcaps  : bool, default = True
If `True`, will toggle on the rendering of the caps
showbox  : bool, default = True
If `True`, will toggle on the rendering of the box
showfliers : bool, default = True
If `True`, will toggle on the rendering of the fliers
boxprops : dict or None (default)
If provided, will set the plotting style of the boxes
whiskerprops : dict or None (default)
If provided, will set the plotting style of the whiskers
capprops : dict or None (default)
If provided, will set the plotting style of the caps
flierprops : dict or None (default)
If provided will set the plotting style of the fliers
medianprops : dict or None (default)
If provided, will set the plotting style of the medians
meanprops : dict or None (default)
If provided, will set the plotting style of the means
meanline : bool, default = False
If `True` (and *showmeans* is `True`), will try to render the mean
as a line spanning the full width of the box according to
*meanprops*. Not recommended if *shownotches* is also True.
Otherwise, means will be shown as points.
manage_xticks : bool, default = True
If the function should adjust the xlim and xtick locations.
zorder : scalar,  default = None
The zorder of the resulting boxplot
Returns
result : dict
A dictionary mapping each component of the boxplot to a list
of the :class:`matplotlib.lines.Line2D` instances
created. That dictionary has the following keys (assuming
vertical boxplots):
- ``boxes``: the main body of the boxplot showing the
quartiles and the median\'s confidence intervals if
enabled.
- ``medians``: horizontal lines at the median of each box.
- ``whiskers``: the vertical lines extending to the most
extreme, non-outlier data points.
- ``caps``: the horizontal lines at the ends of the
whiskers.
- ``fliers``: points representing data that extend beyond
the whiskers (fliers).
- ``means``: points or lines representing the means.
Examples
.. plot:: gallery/statistics/bxp.py'

def bxp(self, bxpstats, positions=None, widths=None, vert=True, patch_artist=False, shownotches=False, showmeans=False, showcaps=True, showbox=True, showfliers=True, boxprops=None, whiskerprops=None, flierprops=None, medianprops=None, capprops=None, meanprops=None, meanline=False, manage_xticks=True, zorder=None):

    whiskers = []
    caps = []
    boxes = []
    medians = []
    means = []
    fliers = []
    datalabels = []
    if (zorder is None):
        zorder = mlines.Line2D.zorder
    zdelta = 0.1
    if patch_artist:
        final_boxprops = dict(linestyle=rcParams[u'boxplot.boxprops.linestyle'], edgecolor=rcParams[u'boxplot.boxprops.color'], facecolor=rcParams[u'patch.facecolor'], linewidth=rcParams[u'boxplot.boxprops.linewidth'])
        if rcParams[u'_internal.classic_mode']:
            final_boxprops[u'facecolor'] = u'white'
    else:
        final_boxprops = dict(linestyle=rcParams[u'boxplot.boxprops.linestyle'], color=rcParams[u'boxplot.boxprops.color'])
    final_boxprops[u'zorder'] = zorder
    if (boxprops is not None):
        final_boxprops.update(boxprops)
    final_whiskerprops = dict(linestyle=rcParams[u'boxplot.whiskerprops.linestyle'], linewidth=rcParams[u'boxplot.whiskerprops.linewidth'], color=rcParams[u'boxplot.whiskerprops.color'])
    final_capprops = dict(linestyle=rcParams[u'boxplot.capprops.linestyle'], linewidth=rcParams[u'boxplot.capprops.linewidth'], color=rcParams[u'boxplot.capprops.color'])
    final_capprops[u'zorder'] = zorder
    if (capprops is not None):
        final_capprops.update(capprops)
    final_whiskerprops[u'zorder'] = zorder
    if (whiskerprops is not None):
        final_whiskerprops.update(whiskerprops)
    final_flierprops = dict(linestyle=rcParams[u'boxplot.flierprops.linestyle'], linewidth=rcParams[u'boxplot.flierprops.linewidth'], color=rcParams[u'boxplot.flierprops.color'], marker=rcParams[u'boxplot.flierprops.marker'], markerfacecolor=rcParams[u'boxplot.flierprops.markerfacecolor'], markeredgecolor=rcParams[u'boxplot.flierprops.markeredgecolor'], markersize=rcParams[u'boxplot.flierprops.markersize'])
    final_flierprops[u'zorder'] = zorder
    if (flierprops is not None):
        final_flierprops.update(flierprops)
    final_medianprops = dict(linestyle=rcParams[u'boxplot.medianprops.linestyle'], linewidth=rcParams[u'boxplot.medianprops.linewidth'], color=rcParams[u'boxplot.medianprops.color'])
    final_medianprops[u'zorder'] = (zorder + zdelta)
    if (medianprops is not None):
        final_medianprops.update(medianprops)
    if meanline:
        final_meanprops = dict(linestyle=rcParams[u'boxplot.meanprops.linestyle'], linewidth=rcParams[u'boxplot.meanprops.linewidth'], color=rcParams[u'boxplot.meanprops.color'])
    else:
        final_meanprops = dict(linestyle=u'', marker=rcParams[u'boxplot.meanprops.marker'], markerfacecolor=rcParams[u'boxplot.meanprops.markerfacecolor'], markeredgecolor=rcParams[u'boxplot.meanprops.markeredgecolor'], markersize=rcParams[u'boxplot.meanprops.markersize'])
    final_meanprops[u'zorder'] = (zorder + zdelta)
    if (meanprops is not None):
        final_meanprops.update(meanprops)
    def to_vc(xs, ys):
        verts = list(zip(xs, ys))
        verts.append((0, 0))
        codes = (([mpath.Path.MOVETO] + ([mpath.Path.LINETO] * (len(verts) - 2))) + [mpath.Path.CLOSEPOLY])
        return (verts, codes)
    def patch_list(xs, ys, **kwargs):
        (verts, codes) = to_vc(xs, ys)
        path = mpath.Path(verts, codes)
        patch = mpatches.PathPatch(path, **kwargs)
        self.add_artist(patch)
        return [patch]
    if vert:
        def doplot(*args, **kwargs):
            return self.plot(*args, **kwargs)
        def dopatch(xs, ys, **kwargs):
            return patch_list(xs, ys, **kwargs)
    else:
        def doplot(*args, **kwargs):
            shuffled = []
            for i in xrange(0, len(args), 2):
                shuffled.extend([args[(i + 1)], args[i]])
            return self.plot(*shuffled, **kwargs)
        def dopatch(xs, ys, **kwargs):
            (xs, ys) = (ys, xs)
            return patch_list(xs, ys, **kwargs)
    N = len(bxpstats)
    datashape_message = u'List    of    boxplot    statistics    and    `{0}`    values    must    have    same    the    length'
    if (positions is None):
        positions = list(xrange(1, (N + 1)))
    elif (len(positions) != N):
        raise ValueError(datashape_message.format(u'positions'))
    if (widths is None):
        widths = ([np.clip((0.15 * np.ptp(positions)), 0.15, 0.5)] * N)
    elif np.isscalar(widths):
        widths = ([widths] * N)
    elif (len(widths) != N):
        raise ValueError(datashape_message.format(u'widths'))
    if (not self._hold):
        self.cla()
    holdStatus = self._hold
    for (pos, width, stats) in zip(positions, widths, bxpstats):
        datalabels.append(stats.get(u'label', pos))
        whisker_x = (np.ones(2) * pos)
        whiskerlo_y = np.array([stats[u'q1'], stats[u'whislo']])
        whiskerhi_y = np.array([stats[u'q3'], stats[u'whishi']])
        cap_left = (pos - (width * 0.25))
        cap_right = (pos + (width * 0.25))
        cap_x = np.array([cap_left, cap_right])
        cap_lo = (np.ones(2) * stats[u'whislo'])
        cap_hi = (np.ones(2) * stats[u'whishi'])
        box_left = (pos - (width * 0.5))
        box_right = (pos + (width * 0.5))
        med_y = [stats[u'med'], stats[u'med']]
        if shownotches:
            box_x = [box_left, box_right, box_right, cap_right, box_right, box_right, box_left, box_left, cap_left, box_left, box_left]
            box_y = [stats[u'q1'], stats[u'q1'], stats[u'cilo'], stats[u'med'], stats[u'cihi'], stats[u'q3'], stats[u'q3'], stats[u'cihi'], stats[u'med'], stats[u'cilo'], stats[u'q1']]
            med_x = cap_x
        else:
            box_x = [box_left, box_right, box_right, box_left, box_left]
            box_y = [stats[u'q1'], stats[u'q1'], stats[u'q3'], stats[u'q3'], stats[u'q1']]
            med_x = [box_left, box_right]
        if showbox:
            if patch_artist:
                boxes.extend(dopatch(box_x, box_y, **final_boxprops))
            else:
                boxes.extend(doplot(box_x, box_y, **final_boxprops))
        whiskers.extend(doplot(whisker_x, whiskerlo_y, **final_whiskerprops))
        whiskers.extend(doplot(whisker_x, whiskerhi_y, **final_whiskerprops))
        if showcaps:
            caps.extend(doplot(cap_x, cap_lo, **final_capprops))
            caps.extend(doplot(cap_x, cap_hi, **final_capprops))
        medians.extend(doplot(med_x, med_y, **final_medianprops))
        if showmeans:
            if meanline:
                means.extend(doplot([box_left, box_right], [stats[u'mean'], stats[u'mean']], **final_meanprops))
            else:
                means.extend(doplot([pos], [stats[u'mean']], **final_meanprops))
        if showfliers:
            flier_x = (np.ones(len(stats[u'fliers'])) * pos)
            flier_y = stats[u'fliers']
            fliers.extend(doplot(flier_x, flier_y, **final_flierprops))
    if vert:
        setticks = self.set_xticks
        setlim = self.set_xlim
        setlabels = self.set_xticklabels
    else:
        setticks = self.set_yticks
        setlim = self.set_ylim
        setlabels = self.set_yticklabels
    if manage_xticks:
        newlimits = ((min(positions) - 0.5), (max(positions) + 0.5))
        setlim(newlimits)
        setticks(positions)
        setlabels(datalabels)
    self._hold = holdStatus
    return dict(whiskers=whiskers, caps=caps, boxes=boxes, medians=medians, fliers=fliers, means=means)
