Violin图与箱形图相似,不同之处在于它们还显示了数据在不同值处的概率密度,在该箱形图上叠加了内核密度估计。像箱形图一样,Violin图用来表示跨不同"类别"的变量分布(或样本分布)的比较。
Violin图比普通箱图更具信息性。实际上,虽然箱形图仅显示汇总统计信息,如均值/中位数和四分位数范围,但Violin图却显示了数据的完整分布。
import matplotlib.pyplot as plt np.random.seed(10) collectn_1 = np.random.normal(100, 10, 200) collectn_2 = np.random.normal(80, 30, 200) collectn_3 = np.random.normal(90, 20, 200) collectn_4 = np.random.normal(70, 25, 200) ## combine these different collections into a list data_to_plot = [collectn_1, collectn_2, collectn_3, collectn_4] # Create a figure instance fig = plt.figure() # Create an axes instance ax = fig.add_axes([0,0,1,1]) # Create the boxplot bp = ax.violinplot(data_to_plot) plt.show()
这一章你学到了什么?做个笔记,好记忆不如烂笔头! 请将遇到的问题写入评论区中,大家一起进步。
祝学习愉快!(您也可以 选中需要修改的内容->右键->进行编辑)