Seaborn入门(三): 实现Violinplots

小提琴图(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)

下边试举几例:

import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x=tips["total_bill"])
simple
ax = sns.violinplot(x="day", y="total_bill", data=tips)
vertical

分组:

ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
                    data=tips, palette="muted")
group

将两组合到一起:

ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
                    data=tips, palette="muted", split=True)
image.png

加上四分位数:

ax = sns.violinplot(x="day", y="total_bill", hue="sex",
                    data=tips, palette="Set2", split=True,
                    scale="count", inner="quartile")
quartiles

catplot分面:

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

欢迎关注!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容