引言
python数据可视化的包有matplotlib,seaborn等。
Seaborn其实是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易,在大多数情况下使用seaborn就能做出很具有吸引力的图,而使用matplotlib就能制作具有更多特色的图。
应该把Seaborn视为matplotlib的补充,而不是替代物。
1. catplot
分类估计图
seaborn.catplot(x=None, y=None, hue=None, data=None, row=None, col=None, col_wrap=None,
estimator=<function mean>, 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)
>>> import seaborn as sns
>>> sns.set(style="ticks")
>>> exercise = sns.load_dataset("exercise")
>>> g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
# 条形图,利用bar来画出每个类别的平均值
# 黑色表示估计区间
titanic = sns.load_dataset("titanic")
sns.catplot(x="sex", y="survived", hue="class",kind="bar", data=titanic);
参考:
- 数据可视化(三)- Seaborn简易入门;
- Seaborn example gallery;
- seaborn.catplot;
- zhihu seaborn