Python中的 Matplotlib.axes.Axes.boxplot()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.boxplot()函数
matplotlib 库的 axes 模块中的Axes.boxplot()函数用于为 x 的每一列或序列 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.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.boxplot()函数:
示例 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()
输出:
示例 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()
输出: