matplotlib.pyplot.boxplot — Matplotlib 3.9.1 documentation (2024)

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, tick_labels=None, flierprops=None, medianprops=None, meanprops=None, capprops=None, whiskerprops=None, manage_ticks=True, autorange=False, zorder=None, capwidths=None, label=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.The whiskers extend from the box to the farthest data pointlying within 1.5x the inter-quartile range (IQR) from the box.Flier points are those past the end of the whiskers.See https://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 columnin x. If a sequence of 1D arrays, a boxplot is drawn for eacharray in x.

notchbool, default: rcParams["boxplot.notch"] (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 for bootstrapdescribes 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. If None, then the fliers default to 'b+'. Morecontrol is provided by the flierprops parameter.

vertbool, default: rcParams["boxplot.vertical"] (default: True)

If True, draws vertical boxes.If False, 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 datumbelow Q3 + whis*(Q3-Q1), where Q1 and Q3 are the first andthird quartiles. The default value of whis = 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 where Q1 == Q3, whis is automatically setto (0, 100) (cover the whole range of the data) if autorange 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. If bootstrap 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 length len(x). Each entry that is notNone forces the value of the median for the correspondingdataset. For entries that are None, 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 if notch is True). For entries that are None,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, or 0.15*(distancebetween extreme positions), if that is smaller.

patch_artistbool, default: rcParams["boxplot.patchartist"] (default: False)

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

tick_labelslist of str, optional

The tick labels of each boxplot.Ticks are always placed at the box positions. If tick_labels is given,the ticks are labelled accordingly. Otherwise, they keep their numericvalues.

Changed in version 3.9: Renamed from labels, which is deprecated since 3.9and will be removed in 3.11.

manage_ticksbool, default: True

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

autorangebool, default: False

When True 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: rcParams["boxplot.meanline"] (default: False)

If True (and showmeans is True), will try to render themean as a line spanning the full width of the box according tomeanprops (see below). Not recommended if shownotches 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 the Line2D 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: rcParams["boxplot.showcaps"] (default: True)

Show the caps on the ends of whiskers.

showboxbool, default: rcParams["boxplot.showbox"] (default: True)

Show the central box.

showfliersbool, default: rcParams["boxplot.showfliers"] (default: True)

Show the outliers beyond the caps.

showmeansbool, default: rcParams["boxplot.showmeans"] (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.

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"]); if patch_artist is True, the legendwill show the box Patch artists (result["boxes"]) instead.

New in version 3.9.

dataindexable object, optional

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

See also

Axes.bxp

Draw a boxplot from pre-computed statistics.

violinplot

Draw an estimate of the probability density function.

Notes

Note

This is the pyplot wrapper for axes.Axes.boxplot.

Examples using matplotlib.pyplot.boxplot#

matplotlib.pyplot.boxplot — Matplotlib 3.9.1 documentation (1)

Artist customization in box plots

Artist customization in box plots

matplotlib.pyplot.boxplot — Matplotlib 3.9.1 documentation (2)

Box plots with custom fill colors

Box plots with custom fill colors

matplotlib.pyplot.boxplot — Matplotlib 3.9.1 documentation (3)

Boxplots

Boxplots

matplotlib.pyplot.boxplot — Matplotlib 3.9.1 documentation (4)

Box plot vs. violin plot comparison

Box plot vs. violin plot comparison

matplotlib.pyplot.boxplot — Matplotlib 3.9.1 documentation (2024)

FAQs

What is patch_artist? ›

patch_artist : If True , the boxes will be filled with color. labels : This parameter is used to pass in a list of labels to be used for each dataset. meanline : If True , a line is drawn at the mean value of each dataset.

What is the correct combination of function and parameter to create a box plot in matplotlib? ›

Creating Box Plot

pyplot module of matplotlib library provides boxplot() function with the help of which we can create box plots. The data values given to the ax. boxplot() method can be a Numpy array or Python list or Tuple of arrays.

How do you graph a boxplot? ›

To construct a box plot, use a horizontal or vertical number line and a rectangular box. The smallest and largest data values label the endpoints of the axis. The first quartile marks one end of the box and the third quartile marks the other end of the box.

What does a box plot tell you? ›

Box plots are used to show distributions of numeric data values, especially when you want to compare them between multiple groups. They are built to provide high-level information at a glance, offering general information about a group of data's symmetry, skew, variance, and outliers.

What is the syntax of Boxplot? ›

Boxplots can be created for individual variables or for variables by group. The format is boxplot(x, data=), where x is a formula and data= denotes the data frame providing the data. An example of a formula is y~group where a separate boxplot for numeric variable y is generated for each value of group.

What insights can we extract from the boxplot? ›

Box plots provide a quick visual summary of the variability of values in a dataset. They show the median, upper and lower quartiles, minimum and maximum values, and any outliers in the dataset. Outliers can reveal mistakes or unusual occurrences in data.

What do notches represent in a boxplot? ›

The notched boxplot allows you to evaluate confidence intervals (by default 95 percent confidence interval) for the medians of each boxplot.

What are whiskers in a boxplot? ›

Sometimes, the mean is also indicated by a dot or a cross on the box plot. The whiskers are the two lines outside the box, that go from the minimum to the lower quartile (the start of the box) and then from the upper quartile (the end of the box) to the maximum.

How do I show a boxplot in pandas Python? ›

One way to plot boxplot using pandas dataframe is to use boxplot() function that is part of pandas library.

Top Articles
You Have Pear Face Shape? – PinkMirror Blog
hairstyles for the trapezoid type, hairstyle for fine hair, the right makeup, whether the bangs
Marcial Quinones Useless MBA: 1500 applications & still no job!
Sarah Burton Is Givenchy's New Creative Director
Hsqa Online Renewal System
Suppression du CESE et du HCCT au Sénégal : L'Assemblée nationale vote contre la suppression de ces deux institutions - BBC News Afrique
Lamb Funeral Home Obituaries Columbus Ga
Baue Recent Obituaries
Https Paperlesspay Talx Com Boydgaming
Indio Mall Eye Doctor
Void Client Vrchat
Dr. med. Dupont, Allgemeinmediziner in Aachen
Joann Ally Employee Portal
Castle Nail Spa (Plano)
29 Best Free Sports Streaming Sites | Sept. 2024 (No Ads!)
Cooktopcove Com
20 Cozy and Creative Fall Front Porch Ideas to Welcome the Season in Style
Csgo Themed Inventory
Convert liters to quarts
Overton Funeral Home Waterloo Iowa
Tyrone Unblocked Games Bitlife
Winnie The Pooh Sewing Meme
David Knowles, journalist who helped make the Telegraph podcast Ukraine: The Latest a runaway success
Dreamhorse For Sale
Axolotls for Sale - 10 Online Stores You Can Buy an Axolotl - Axolotl Nerd
Think Up Elar Level 5 Answer Key Pdf
Craigslist Apts Near Me
Uhaul L
Receive Sms Verification
Runescape Abyssal Beast
Gustavo Naspolini Relationship
New Homes in Waterleigh | Winter Garden, FL | D.R. Horton
Los Garroberros Menu
Yillian Atkinson Velez
Craigslist Chicagoland Area
How to get tink dissipator coil? - Dish De
Boone County Sheriff 700 Report
Shaleback Hollow Location
How To Use Price Chopper Points At Quiktrip
Riverwood Family Services
Brian Lizer Life Below Zero Next Generation
Agility Armour Conan Exiles
Rexella Van Impe Net Worth
Los Alamos Beach in Torremolinos: A Perfect Mediterranean Escape - Mama Málaga
Thotsbay New Site
Htmp Hilton
Culver's Flavor Of The Day Little Chute
Delta Rastrear Vuelo
Melisa Mendini Wiki, Age, Boyfriend, Height, Career, Photos
Greythr Hexaware Bps
Munich Bavaria Germany 15 Day Weather Forecast
Right Wrist Itching Superstition
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 5871

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.