seaborn.catplot(x=None, y=None, hue=None, data=None, row=None, col=None, col_wrap=None, estimator=, ci=95, n_boot=1000, units=None, order=None, hue_order=None, row_order=None, col_order=None, kind='strip', height=5, aspect=1, orient=None, color=None, palette=None, legend=True, legend_out=True, sharex=True, sharey=True, margin_titles=False, facet_kws=None, **kwargs)
通过kind生成不同类别的图, kind的取值有: strip, swarm, box, violin,boxen,point, bar, count. strip为默认值.
数据取样:
exercise = sns.load_dataset("exercise")
logger.info("data sample:\n%s", exercise.sample(10))
Unnamed: 0 id diet pulse time kind
6 6 3 low fat 97 1 min rest
7 7 3 low fat 97 15 min rest
9 9 4 low fat 80 1 min rest
64 64 22 low fat 104 15 min running
74 74 25 low fat 116 30 min running
39 39 14 low fat 95 1 min walking
54 54 19 no fat 97 1 min walking
53 53 18 no fat 101 30 min walking
32 32 11 low fat 84 30 min walking
66 66 23 low fat 98 1 min running
1) 基本图
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
2) kind=violin
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise, kind="violin")
3) col参数, 指定某一切面来考察数据
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise)
4) 考察切面时, 利用height, aspect参数
height : scalar, optional
Height (in inches) of each facet. See also:
aspect
.
aspect : scalar, optional
Aspect ratio of each facet, so that
aspect * height
gives the width of each facet in inches.
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise, height=5, aspect=.8)
5) 切面时, 使用参数 col_wrap, 指定每排展示的个数.
g = sns.catplot(x="time", y="pulse", hue="kind", col="kind", col_wrap=2, data=exercise, height=5, aspect=.8)
可以看出, 每排被限定到了2个.
来自:
1) http://seaborn.pydata.org/generated/seaborn.catplot.html#seaborn.catplot