Seaborn入门(三): 实现Violinplots

2020-04-01 16:11:46 浏览数 (1)

小提琴图(violinplot)结合了箱线图和核密度图,可以反映任意位置的密度。

seaborn.violinplot基本参数为: 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)

下边试举几例:

代码语言:javascript复制
import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x=tips["total_bill"])

simple

代码语言:javascript复制
ax = sns.violinplot(x="day", y="total_bill", data=tips)

vertical

分组:

代码语言:javascript复制
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
                    data=tips, palette="muted")

group

将两组合到一起:

代码语言:javascript复制
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
                    data=tips, palette="muted", split=True)

image.png

加上四分位数:

代码语言:javascript复制
ax = sns.violinplot(x="day", y="total_bill", hue="sex",
                    data=tips, palette="Set2", split=True,
                    scale="count", inner="quartile")

quartiles

catplot分面:

代码语言:javascript复制
g = sns.catplot(x="sex", y="total_bill",
                hue="smoker", col="time",
                data=tips, kind="violin", split=True,
                height=4, aspect=.7)

catplot

欢迎关注公众号~

生信编程日常

0 人点赞