Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

matplotlib.pyplot.boxplot#

matplotlib.pyplot.boxplot(x,notch=None,sym=None,vert=None,whis=None,positions=None,widths=None,patch_artist=None,bootstrap=None,usermedians=None,conf_intervals=None,meanline=None,showmeans=None,showcaps=None,showbox=None,showfliers=None,boxprops=None,labels=None,flierprops=None,medianprops=None,meanprops=None,capprops=None,whiskerprops=None,manage_ticks=True,autorange=False,zorder=None,capwidths=None,*,data=None)[source]#

Draw a box and whisker plot.

The box extends from the first quartile (Q1) to the thirdquartile (Q3) of the data, with a line at the median. Thewhiskers extend from the box by 1.5x the inter-quartile range(IQR). Flier points are those past the end of the whiskers.Seehttps://en.wikipedia.org/wiki/Box_plot for reference.

     Q1-1.5IQR   Q1   median  Q3   Q3+1.5IQR                  |-----:-----|  o      |--------|     :     |--------|    o  o                  |-----:-----|flier             <----------->            fliers                       IQR
Parameters:
xArray or a sequence of vectors.

The input data. If a 2D array, a boxplot is drawn for each columninx. If a sequence of 1D arrays, a boxplot is drawn for eacharray inx.

notchbool, default: False

Whether to draw a notched boxplot (True), or a rectangularboxplot (False). The notches represent the confidence interval(CI) around the median. The documentation forbootstrapdescribes how the locations of the notches are computed bydefault, but their locations may also be overridden by setting theconf_intervals parameter.

Note

In cases where the values of the CI are less than thelower quartile or greater than the upper quartile, thenotches will extend beyond the box, giving it adistinctive "flipped" appearance. This is expectedbehavior and consistent with other statisticalvisualization packages.

symstr, optional

The default symbol for flier points. An empty string ('') hidesthe fliers. IfNone, then the fliers default to 'b+'. Morecontrol is provided by theflierprops parameter.

vertbool, default: True

IfTrue, draws vertical boxes.IfFalse, draw horizontal boxes.

whisfloat or (float, float), default: 1.5

The position of the whiskers.

If a float, the lower whisker is at the lowest datum aboveQ1-whis*(Q3-Q1), and the upper whisker at the highest datumbelowQ3+whis*(Q3-Q1), where Q1 and Q3 are the first andthird quartiles. The default value ofwhis=1.5 correspondsto Tukey's original definition of boxplots.

If a pair of floats, they indicate the percentiles at which todraw the whiskers (e.g., (5, 95)). In particular, setting this to(0, 100) results in whiskers covering the whole range of the data.

In the edge case whereQ1==Q3,whis is automatically setto (0, 100) (cover the whole range of the data) ifautorange isTrue.

Beyond the whiskers, data are considered outliers and are plottedas individual points.

bootstrapint, optional

Specifies whether to bootstrap the confidence intervalsaround the median for notched boxplots. Ifbootstrap isNone, no bootstrapping is performed, and notches arecalculated using a Gaussian-based asymptotic approximation(see McGill, R., Tukey, J.W., and Larsen, W.A., 1978, andKendall and Stuart, 1967). Otherwise, bootstrap specifiesthe number of times to bootstrap the median to determine its95% confidence intervals. Values between 1000 and 10000 arerecommended.

usermedians1D array-like, optional

A 1D array-like of lengthlen(x). Each entry that is notNone forces the value of the median for the correspondingdataset. For entries that areNone, the medians are computedby Matplotlib as normal.

conf_intervalsarray-like, optional

A 2D array-like of shape(len(x),2). Each entry that is notNone forces the location of the corresponding notch (which isonly drawn ifnotch isTrue). For entries that areNone,the notches are computed by the method specified by the otherparameters (e.g.,bootstrap).

positionsarray-like, optional

The positions of the boxes. The ticks and limits areautomatically set to match the positions. Defaults torange(1,N+1) where N is the number of boxes to be drawn.

widthsfloat or array-like

The widths of the boxes. The default is 0.5, or0.15*(distancebetweenextremepositions), if that is smaller.

patch_artistbool, default: False

IfFalse produces boxes with the Line2D artist. Otherwise,boxes are drawn with Patch artists.

labelssequence, optional

Labels for each dataset (one per dataset).

manage_ticksbool, default: True

If True, the tick locations and labels will be adjusted to matchthe boxplot positions.

autorangebool, default: False

WhenTrue and the data are distributed such that the 25th and75th percentiles are equal,whis is set to (0, 100) suchthat the whisker ends are at the minimum and maximum of the data.

meanlinebool, default: False

IfTrue (andshowmeans isTrue), will try to render themean as a line spanning the full width of the box according tomeanprops (see below). Not recommended ifshownotches is alsoTrue. Otherwise, means will be shown as points.

zorderfloat, default:Line2D.zorder=2

The zorder of the boxplot.

Returns:
dict

A dictionary mapping each component of the boxplot to a listof theLine2D instances created. That dictionary has thefollowing keys (assuming vertical boxplots):

  • boxes: the main body of the boxplot showing thequartiles and the median's confidence intervals ifenabled.

  • medians: horizontal lines at the median of each box.

  • whiskers: the vertical lines extending to the mostextreme, non-outlier data points.

  • caps: the horizontal lines at the ends of thewhiskers.

  • fliers: points representing data that extend beyondthe whiskers (fliers).

  • means: points or lines representing the means.

Other Parameters:
showcapsbool, default: True

Show the caps on the ends of whiskers.

showboxbool, default: True

Show the central box.

showfliersbool, default: True

Show the outliers beyond the caps.

showmeansbool, default: False

Show the arithmetic means.

cappropsdict, default: None

The style of the caps.

capwidthsfloat or array, default: None

The widths of the caps.

boxpropsdict, default: None

The style of the box.

whiskerpropsdict, default: None

The style of the whiskers.

flierpropsdict, default: None

The style of the fliers.

medianpropsdict, default: None

The style of the median.

meanpropsdict, default: None

The style of the mean.

dataindexable object, optional

If given, all parameters also accept a strings, which isinterpreted asdata[s] (unless this raises an exception).

See also

violinplot

Draw an estimate of the probability density function.

On this page

[8]ページ先頭

©2009-2025 Movatter.jp