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

ax = sns.violinplot(x="day", y="total_bill", data=tips)

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

将两组合到一起:
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips, palette="muted", split=True)

加上四分位数:
ax = sns.violinplot(x="day", y="total_bill", hue="sex",
data=tips, palette="Set2", split=True,
scale="count", inner="quartile")

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

欢迎关注公众号~

网友评论