Matplotlib是Python中令人惊叹的可视化库,用于二维阵列图。Matplotlib是一个基于NumPy数组的多平台数据可视化库,旨在与更广泛的SciPy堆栈配合使用。
顾名思义,matplotlib.pyplot.violinplot()用于制作小提琴图。通过此函数,您可以为数据集的每一列或数据集序列中的每个向量绘制小提琴图。所有填充区域均扩展为显示整个数据范围,其中的线在平均值,中位数,最大值和最小值处为可选。
用法:matplotlib.pyplot.violinplot(dataset,positions=None,vert=True,widths=0.5,showmeans=False,showextrema=True,showmedians=False,points=100,bw_method=None,*,data=None)参数:
返回值:此函数将violin-plot的每个组件的字典映射返回到各个集合实例的列表。返回的字典具有以下键:
范例1:
importnumpyasnpimportmatplotlib.pyplotaspltnp.random.seed(21)data=np.random.random(111)quartile1,median,quartile3=np.percentile(data,[50,75,100],axis=0)plt.violinplot(data)plt.vlines(1,quartile1,quartile3,color='r',linestyle='--')plt.hlines(quartile1,.7,1.2)plt.hlines(quartile3,.7,1.2)输出:
范例2:
importmatplotlib.pyplotasplt#Fixingrandomstatefor#reproducibilitynp.random.seed(15437660)#creatingrandomlygenerate#collections/datacoll_1=np.random.normal(100,10,200)coll_2=np.random.normal(80,30,200)coll_3=np.random.normal(90,20,200)coll_4=np.random.normal(70,25,200)##combiningthesedifferent#collectionsintoalistdata_plotter=[coll_1,coll_2,coll_3,coll_4]plt.violinplot(data_plotter)plt.show()