def stat_all_by_rank(self):
ranks = ['??', '??', '??', '??', '????', '????']
men_infos = Info.objects.filter(gender = '?')
women_infos = Info.objects.filter(gender = '?')
men_ranks = [i.get_rank() for i in men_infos]
women_ranks = [i.get_rank() for i in women_infos]
men_count = [men_ranks.count(r) for r in ranks]
women_count = [women_ranks.count(r) for r in ranks]
ind = np.arange(6)
width = 0.35
fig, ax = pl.subplots(figsize = (5.2, 2.8))
rects1 = ax.bar(ind, men_count, width, color = '#20b2aa')
rects2 = ax.bar(ind + width, women_count, width, color = 'w')
ax.set_ylabel('??', fontproperties = zhfont)
ax.set_xlim(-0.5, 7)
ax.set_xticks(ind+width)
ax.set_xticklabels(ranks, fontproperties = zhfont)
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'), fontsize = 'small')
def autolabel(rects):
for rect in rects:
height = rect.get_height()
ax.text(
rect.get_x() + rect.get_width() / 2,
1.05 * height,
'%d' % int(height),
ha = 'center',
va='bottom',
)
autolabel(rects1)
autolabel(rects2)
fig.savefig(self.file_path + 'all1.jpg')
fig.clear()
评论列表
文章目录