Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.
matplotlib.axes.Axes.boxplot() Function
The Axes.boxplot() function in axes module of matplotlib library is used to make a box and whisker plot for each column of x or each vector in sequence x.
Syntax: Axes.boxplot(self, 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, *, data=None)
Parameters: This method accept the following parameters that are described below:
- x: This parameter is a sequence of data.
- notch: This parameter will produce a notched box plot if true. Otherwise, a rectangular boxplot is produced.
- sym : This parameter is an optional parameter and contain string value. It is a default symbol for flier points.
- vert: This parameter is an optional parameter and contain boolean value. It makes the boxes vertical if true.Otherwise horizontal.
- whis : This parameter determines the reach of the whiskers to the beyond the first and third quartiles.
- bootstrap : This parameter is also an optional parameter which contain boolean value and specifies whether to bootstrap the confidence intervals around the median for notched boxplots.
- usermedians : This parameter is an array or sequence whose first dimension is compatible with x.
- conf_intervals : This parameter is also an array or sequence whose first dimension is compatible with x and whose second dimension is 2
- positions : This parameter is used to sets the positions of the boxes.
- widths: This parameter is used to sets the width of each box either with a scalar or a sequence.
- patch_artist : This parameter is used to produce boxes with the Line2D artist if it is false. Otherwise, boxes with Patch artists.
- labels : This parameter is the labels for each dataset.
- manage_ticks : This parameter is used to adjust the tick locations and labels.
- zorder : This parameter is used to sets the zorder of the boxplot.
Returns: This returns the following:
- result :This returns the dictionary which maps each component of the boxplot to a list of the matplotlib.lines.Line2D.
Below examples illustrate the matplotlib.axes.Axes.boxplot() function in matplotlib.axes:
Example-1:
# Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt np.random.seed( 10 * * 7 ) val1 = np.random.rand( 50 ) * 80 val2 = np.ones( 80 ) * 50 val3 = np.random.rand( 50 ) * 80 + 100 val4 = np.random.rand( 50 ) * - 80 data = np.concatenate((val1, val2, val3, val4)) fig1, ax1 = plt.subplots() ax1.boxplot(data) ax1.set_title( 'matplotlib.axes.Axes.boxplot() Example' ) plt.show() |
Output:
Example-2:
# Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt np.random.seed( 10 * * 7 ) val1 = np.random.rand( 50 ) * 80 val2 = np.ones( 25 ) * 80 val3 = np.random.rand( 25 ) * 80 + 100 val4 = np.random.rand( 25 ) * - 80 data = np.concatenate((val1, val2, val3, val4)) data1 = np.concatenate((val2, val4, val1, val3)) data = [data, data1] fig1, ax1 = plt.subplots() ax1.boxplot(data, notch = True , vert = False , whis = 0.75 ) ax1.set_title( 'matplotlib.axes.Axes.boxplot() Example' ) plt.show() |
Output: