Python – seaborn.boxenplot() 方法
先决条件: Seaborn 的基础知识
Seaborn 是一个基于 matplotlib 的Python数据可视化库。它提供了一个用于绘制有吸引力和信息丰富的统计图形的高级界面。精心设计的可视化有一些非凡之处。颜色突出,层次很好地融合在一起,轮廓贯穿始终,整体包装不仅具有良好的美学品质,而且还为我们提供了有意义的见解。
seaborn.boxenplot()
为较大的数据集绘制增强的箱线图。这种绘图风格最初被命名为“字母值”绘图,因为它显示了大量定义为“字母值”的分位数。它类似于绘制一个分布的非参数表示的箱线图,其中所有特征都对应于实际观察值。通过绘制更多的分位数,它提供了关于分布形状的更多信息,尤其是在尾部。
Syntax : seaborn.boxenplot(parameters)
Parameters :
- x, y, hue : Inputs for plotting long-form data.
- data : Dataset for plotting.
- order, hue_order : Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
- orient : Orientation of the plot (vertical or horizontal).
- color : Color for all of the elements, or seed for a gradient palette.
- palette : Colors to use for the different levels of the hue variable.
- saturation : Proportion of the original saturation to draw colors at.
- width : Width of a full element when not using hue nesting, or width of all the elements for one level of the major grouping variable.
- dodge : When hue nesting is used, whether elements should be shifted along the categorical axis.
- k_depth : The number of boxes, and by extension number of percentiles, to draw.
- linewidth : Width of the gray lines that frame the plot elements.
- scale : Method to use for the width of the letter value boxes.
- outlier_prop : Proportion of data believed to be outliers.
- showfliers : If False, suppress the plotting of outliers.
- ax : Axes object to draw the plot onto, otherwise uses the current Axes.
- kwargs : Other keyword arguments
Returns : Returns the Axes object with the plot drawn onto it.
以下是上述方法的实现以及一些示例:
示例 1:
# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# plot the boxenplot
sns.boxenplot(x = "day", y = "total_bill",
data = data)
plt.show()
输出 :
示例 2:
# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# plot the boxenplot
# hue by sex
# width of 0.8
sns.boxenplot(x ="day", y = "total_bill", hue = "sex",
data = data, width = 0.8)
plt.show()
输出 :
示例 3:
# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# plot the boxenplot
# orient to horizontal
sns.boxenplot(x = "total_bill", y = "size",
data = data, orient ="h")
plt.show()
输出 :
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。