# 用于数据分析的Violin Plot用法详解

2021年4月13日09:11:10 发表评论 1,895 次浏览

Violin Plot是一种可视化不同变量数值数据分布的方法。它类似于Box Plot, 但每侧都有旋转的图, 从而在y轴上提供了有关密度估计的更多信息。

Violin Plot比box plot具有更多的信息, 它们不那么受欢迎。由于它们不受欢迎, 对于许多不熟悉Violin Plot表示形式的读者来说, 它们的含义可能更难理解。

``````Attribute Information:
-> sepal length in cm
-> sepal width in cm
-> petal length in cm
-> petal width in cm
-> class:
Iris Setosa
Iris Versicolour
Iris Virginica

Number of Instances: 150

Summary Statistics:
Min  Max   Mean    SD   Class Correlation
sepal length: 4.3  7.9   5.84  0.83    0.7826
sepal width: 2.0  4.4   3.05  0.43   -0.4194
petal length: 1.0  6.9   3.76  1.76    0.9490  (high!)
petal width: 0.1  2.5   1.20  0.76    0.9565  (high!)

Class Distribution: 33.3% for each of 3 classes.``````

``````import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import pyplot
import seaborn``````

``````data = pd.read_csv( "Iris.csv" )

``data.describe()``

``data.info()``

``data[ "SepalLengthCm" ].describe()``

``````count    150.000000
mean       5.843333
std        0.828066
min        4.300000
25%        5.100000
50%        5.800000
75%        6.400000
max        7.900000
Name: SepalLengthCm, dtype: float64``````

" SepalLengthCm"参数的Violin Plot。

``````fig, ax = pyplot.subplots(figsize = ( 9 , 7 ))
sns.violinplot( ax = ax, y = data[ "SepalLengthCm" ] )``````

``````fig, ax = pyplot.subplots(figsize = ( 9 , 7 ))
sns.violinplot(ax = ax, y = data[ "SepalWidthCm" ] )``````

``````fig, ax = pyplot.subplots(figsize = ( 9 , 7 ))
sns.violinplot(ax = ax, data = data.iloc[:, 1 : 3 ])``````

``````fig, ax = pyplot.subplots(figsize = ( 9 , 7 ))
sns.violinplot(ax = ax, x = data[ "Species" ], y = data[ "SepalLengthCm" ] )``````