Matplotlib.axes.Axes.bxp() in Python
Last Updated :
13 Apr, 2020
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The
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.bxp() Function
The
Axes.bxp() 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.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_ticks=True, zorder=None)
Parameters: This method accept the following parameters that are described below:
- bxpstats : This parameter is alist of dictionaries containing stats for each boxplot.
- positions : This parameter is used to sets the positions of the violins.
- vert: This parameter is an optional parameter and contain boolean value. It makes the vertical violin plot if true.Otherwise horizontal.
- widths: This parameter is used to sets the width of each violin 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.
- 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.
- shownotches: This parameter contain boolean value. It is used to produce a notched and rectangular box plot.
- showmeans : This parameter contain boolean value. It is used to toggle rendering of the means.
- showcaps : This parameter contain boolean value. It is used to toggle rendering of the caps.
- showfliers : This parameter contain boolean value. It is used to toggle rendering of the fliers.
- boxprops : This parameter is used to set the plotting style of the boxes.
- whiskerprops : This parameter is used to set the plotting style of the whiskers.
- capprops : This parameter is used to set the plotting style of the caps.
- flierprops : This parameter is used to set the plotting style of the fliers.
- medianprops : This parameter is used to set the plotting style of the medians.
- meanprops : This parameter is used to set the plotting style of the means.
Returns: This returns the following:
- result :This returns the dictionary which maps each component of the violinplot to a list of the matplotlib.lines.Line2D instances.
Below examples illustrate the matplotlib.axes.Axes.bxp() function in matplotlib.axes:
Example-1:
Python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
np.random.seed(10**7)
data = np.random.lognormal(size =(10, 4),
mean = 4.5,
sigma = 4.75)
labels = ['G1', 'G2', 'G3', 'G4']
result = cbook.boxplot_stats(data,
labels = labels,
bootstrap = 1000)
for n in range(len(result)):
result[n]['med'] = np.median(data)
result[n]['mean'] *= 0.1
fig, axes1 = plt.subplots()
axes1.bxp(result)
axes1.set_title('matplotlib.axes.Axes.bxp() Example')
plt.show()
Output:
Example-2:
Python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
np.random.seed(10**7)
data = np.random.lognormal(size =(37, 4),
mean = 4.5,
sigma = 1.75)
labels = ['G1', 'G2', 'G3', 'G4']
stats = cbook.boxplot_stats(data, labels = labels,
bootstrap = 100)
for n in range(len(stats)):
stats[n]['med'] = np.median(data)
stats[n]['mean'] *= 2
fig, [axes1, axes2, axes3] = plt.subplots(nrows = 1,
ncols = 3,
sharey = True)
axes1.bxp(stats)
axes2.bxp(stats, showmeans = True)
axes3.bxp(stats, showmeans = True, meanline = True)
axes2.set_title('matplotlib.axes.Axes.bxp() Example')
plt.show()
Output:
Similar Reads
Matplotlib.axes.Axes.boxplot() in Python 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. matp
3 min read
Matplotlib.axes.Axes.axis() in Python The Axes.axis() function in Matplotlib is used to get or set the properties of the x-axis and y-axis limits on a given Axes object. It provides an easy way to control the view limits, aspect ratio, and visibility of the axes in a plot. It's key feature include:Get the current axis limits as [xmin, x
2 min read
Matplotlib.axes.Axes.axvspan() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The 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.
2 min read
matplotlib.axes.Axes.axhspan() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The 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.
2 min read
Matplotlib.axes.Axes.csd() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The 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.
3 min read