matplotlib.axes.Axes.bxp#
- Axes.bxp(bxpstats,positions=None,*,widths=None,vert=None,orientation='vertical',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_ticks=True,zorder=None,capwidths=None,label=None)[source]#
Draw a box and whisker plot from pre-computed statistics.
The box extends from the first quartileq1 to the thirdquartileq3 of the data, with a line at the median (med).The whiskers extend fromwhislow towhishi.Flier points are markers past the end of the whiskers.Seehttps://en.wikipedia.org/wiki/Box_plot for reference.
whislow q1 med q3 whishi |-----:-----| o |--------| : |--------| o o |-----:-----|flier fliers
Note
This is a low-level drawing function for when you alreadyhave the statistical parameters. If you want a boxplot basedon a dataset, use
boxplotinstead.- Parameters:
- bxpstatslist of dicts
A list of dictionaries containing stats for each boxplot.Required keys are:
med: Median (float).q1,q3: First & third quartiles (float).whislo,whishi: Lower & upper whisker positions (float).
Optional keys are:
mean: Mean (float). Needed ifshowmeans=True.fliers: Data beyond the whiskers (array-like).Needed ifshowfliers=True.cilo,cihi: Lower & upper confidence intervalsabout the median. Needed ifshownotches=True.label: Name of the dataset (str). If available,this will be used a tick label for the boxplot
- positionsarray-like, default: [1, 2, ..., n]
The positions of the boxes. The ticks and limitsare automatically set to match the positions.
- widthsfloat or array-like, default: None
The widths of the boxes. The default is
clip(0.15*(distancebetweenextremepositions),0.15,0.5).- capwidthsfloat or array-like, default: None
Either a scalar or a vector and sets the width of each cap.The default is
0.5*(widthofthebox), seewidths.- vertbool, optional
Deprecated since version 3.11:Useorientation instead.
If this is given during the deprecation period, it overridestheorientation parameter.
If True, plots the boxes vertically.If False, plots the boxes horizontally.
- orientation{'vertical', 'horizontal'}, default: 'vertical'
If 'horizontal', plots the boxes horizontally.Otherwise, plots the boxes vertically.
Added in version 3.10.
- patch_artistbool, default: False
If
Falseproduces boxes with theLine2Dartist.IfTrueproduces boxes with thePatchartist.- shownotches, showmeans, showcaps, showbox, showfliersbool
Whether to draw the CI notches, the mean value (both default toFalse), the caps, the box, and the fliers (all three default toTrue).
- boxprops, whiskerprops, capprops, flierprops, medianprops, meanpropsdict, optional
Artist properties for the boxes, whiskers, caps, fliers, medians, andmeans.
- meanlinebool, default: False
If
True(andshowmeans isTrue), will try to render the meanas a line spanning the full width of the box according tomeanprops. Not recommended ifshownotches is also True.Otherwise, means will be shown as points.- manage_ticksbool, default: True
If True, the tick locations and labels will be adjusted to match theboxplot positions.
- labelstr or list of str, optional
Legend labels. Use a single string when all boxes have the same style andyou only want a single legend entry for them. Use a list of strings tolabel all boxes individually. To be distinguishable, the boxes should bestyled individually, which is currently only possible by modifying thereturned artists, see e.g.Boxplots.
In the case of a single string, the legend entry will technically beassociated with the first box only. By default, the legend will show themedian line (
result["medians"]); ifpatch_artist is True, the legendwill show the boxPatchartists (result["boxes"]) instead.Added in version 3.9.
- zorderfloat, default:
Line2D.zorder=2 The zorder of the resulting boxplot.
- Returns:
- dict
A dictionary mapping each component of the boxplot to a listof the
Line2Dinstances created. That dictionary has thefollowing keys (assuming vertical boxplots):boxes: main bodies of the boxplot showing the quartiles, andthe median's confidence intervals if enabled.medians: horizontal lines at the median of each box.whiskers: vertical lines up to the last non-outlier data.caps: horizontal lines at the ends of the whiskers.fliers: points representing data beyond the whiskers (fliers).means: points or lines representing the means.
See also
boxplotDraw a boxplot from data instead of pre-computed statistics.