手头有一份性别比例的样本数据,清洗后只保留了性别信息,做了一个数据分析。
数据清洗和数据统计的代码就不贴了,贴性别比例pie图和性别比例趋势图的代码。
性别比例pie图:
def _plot_gender_stat_pie(self, fig, gender_stat, title):
"""
fig : figure obj
gender_stat : male / female stat
title : figure title
"""
def _explode(label, target='female'):
if label == target:
return 0.1
else:
return 0
labels = ['male', 'female']
expl = list(map(_explode, labels))
plt.figure(fig, figsize=(7, 7))
plt.pie(gender_stat, explode=expl, labels=labels, autopct="%5.2f%%")
plt.title(title, bbox={'facecolor': '0