# 数据可视化(11)-Seaborn系列 | 小提琴图violinplot()

## 函数原型

```seaborn.violinplot(x=None, y=None, hue=None,
data=None, order=None, hue_order=None,
bw='scott', cut=2, scale='area', scale_hue=True,
gridsize=100, width=0.8, inner='box', split=False,
dodge=True, orient=None, linewidth=None,
color=None, palette=None, saturation=0.75,
ax=None, **kwargs)```

## 参数解读

```输入数据可以通过多种格式传递：
list、numpy数组、pandas
long-form DataFrame
wide-form DataFrame

x,y,hue:数据字段变量名(如上表，date,name,age,sex为数据字段变量名)

data: DataFrame,数组或数组列表

order, hue_order:字符串列表

bw：{'scott'，'silverman'，float}

cut:float

（即，与ggplot中的trim=true具有相同的效果）。

scale：{“area”，“count”，“width”}

gridsize：int

inner:{'box'，'quartile'，'point'，'stick'，None}

split : bool

orient: v | h

linewidth：float

palette：调色板名称,list列表，dict字典

saturation(饱和度)：float

dodge:bool

## 案例教程

```import seaborn as sns
sns.set(style="whitegrid")
tips[:5]```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x=tips['total_bill'])
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="day", y="total_bill", data=tips)
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="day", y="total_bill",
hue="smoker",data=tips, palette="muted")
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips, palette="muted", split=True)
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="time", y="tip",
data=tips,order=["Dinner", "Lunch"])
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="day", y="total_bill", hue="sex",
data=tips, palette="Set2",
split=True,scale="count")
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="day", y="total_bill", hue="sex",
data=tips, palette="Set2", split=True,
scale="count", inner="quartile")
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="day", y="total_bill", hue="sex",
data=tips, palette="Set2", split=True,
scale="count", inner="stick",
scale_hue=False, bw=.2)
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.violinplot(x="orbital_period", y="method",
data=planets[planets.orbital_period < 1000],
scale="width", palette="Set3")
plt.show()```
```import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# 读取数据
"""

"""
sns.catplot(x="sex", y="total_bill",
hue="smoker", col="time",
data=tips, kind="violin", split=True,
height=4, aspect=.7);```

0 条评论