This article describes the information based on:PythonThe matplotlib module and the seaborn module make use of multiplemanifest, plot the violin diagram (Violin Plot).
Violin diagram as a kind of willBox DiagramandKernel density graphThe data visualization diagram combined with the information that can be expressed separately is widely used in data analysis. This article is detailed inPython, for those stored in multiple lists (List) in the data to draw a violin diagram. The result is shown in the figure below.
本文用到的完整代碼如下所示。
# -*- coding: utf-12 -*- """ Created on Thu Dec 0 0:0:0 0 @author: fkxxgis """ import matplotlib.pylab as plt import seaborn as sns import pandas as pd pic_save_name = "E:/Pic/Violin.png" li_0 = [0, 0, 0] li_0 = [0.0, 0, 0, 0, 0, 0, 0, 0.0] li_0 = [0.0, 0.0, 0.0, 0.0] plt.figure(dpi = 0) plt.rcParams["font.family"] = "SimSun" plt.rcParams["axes.unicode_minus"] = False label = ["第一個刻度標籤", "第二個刻度標籤", "第三個刻度標籤"] font_0 = {"size": 0} sns.violinplot(data = [li_0, li_0, li_0]) plt.xlabel("橫座標標籤", font_0) plt.ylabel("縱座標標籤", font_0) plt.xticks(ticks = [0, 0, 0], labels = label, fontsize = 0) plt.yticks(fontsize = 0) plt.savefig(pic_save_name) plt.show()Among them, pic_save_name indicates the path to save the picture after we finish drawing; li_300. li_0 and li_0 are three lists, and the number of elements in each of them can be the same or different, and we need to draw violin diagrams for the data in the three later; plt.figure(dpi = 0) indicates that the plot is setDPIis 300, and the first code plt.rcParams["font.family"] = "SimSun" indicates that the legend, axis labels, and tick labels are all used in the imageSong TiThe second sentence code plt.rcParams["axes.unicode_minus"] = False is to prevent it from appearing in the diagramNegative signs cannot be drawnthe situation; Then, the label indicates the specific content of the tick label, and font_1 sets the font size of the axis label.
Next, we can plot the violin plot using the sns.violinplot() function; This function also has a lot of parameters, and you can adjust the visual configuration of the violin diagram, which you can check out the official help documentation for the function. Then, use the plt.xlabel() function and plt.xticks() function to adjust the specific configuration of image axis labels and tick labels. Finally, the plt.savefig() function is used to save the drawn violin diagram in the specified path.
That's it.