seaborn 的 countplot 计数直方图,可以分类别显示(通过 hue 参数指定)

显示中文:

from matplotlib.font_manager import FontProperties
font = FontProperties(fname='/Library/Fonts/Kaiti.ttc', size=20)

countplot 计数直方图

  • countplot 故名思意,是“计数图”的意思,可将它认为一种应用到分类变量的直方图,也可认为它是用以比较类别间计数差,调用 count 函数的 barplot;

  • countplot 参数和 barplot 基本差不多,可以对比着记忆,有一点不同的是 countplot 中不能同时输入 x 和 y ,且 countplot 没有误差棒。

  • 使用 subplots 绘制多个子图

f, [ax1, ax2, ax3] = plt.subplots(1, 3, figsize=(20, 5))
sns.countplot(x='Sex', hue='Survived', data=data_train, ax=ax1)
sns.countplot(x='Pclass', hue='Survived', data=data_train, ax=ax2)
sns.countplot(x='Embarked', hue='Survived', data=data_train, ax=ax3)
ax1.set_title('Sex 特征分析', fontproperties=font)
ax2.set_title('Pclass 特征分析', fontproperties=font)
ax3.set_title('Embarked 特征分析', fontproperties=font)
# 指定子图的标题
f.suptitle('定类/定序数据类型特征分析', size=20, y=1.1, fontproperties=font)
f, [ax1, ax2] = plt.subplots(1, 2, figsize=(20, 5))
sns.countplot(x='SibSp', hue='Survived', data=data_train, ax=ax1)
sns.countplot(x='Parch', hue='Survived', data=data_train, ax=ax2)
ax1.set_title('SibSp 特征分析', fontproperties=font)
ax2.set_title('Parch 特征分析', fontproperties=font)

seaborn 的 countplot 计数直方图,可以分类别显示(通过 hue 参数指定)_第1张图片

参考资料:
1、seaborn 官方网站
http://seaborn.pydata.org/generated/seaborn.countplot.html
2、【Kaggle入门级竞赛top5%排名经验分享】— 分析篇
https://zhuanlan.zhihu.com/p/40360380
3、【超简单超清楚】mac环境matplotlib的中文配置
https://blog.csdn.net/gmr2453929471/article/details/78655834
4、Seaborn入门系列(二)——barplot&countplot&pointplot
https://www.jianshu.com/p/8bb06d3fd21b

你可能感兴趣的:(数据分析)