前言
python可视化的模块是mtaplotlib,我们要使用它来生成统计图。
示例
import matplotlib.pyplot as plt
import numpy as np
#获取的参数
plt.rcParams['font.sans-serif'] = ['KaiTi']
labels = ['xx项目V1.0', 'xx项目V2.0']
men_means = [47, 26]
women_means = [12, 2]
hui_gui = [4, 3]
x = np.arange(len(labels)) # 标签位置
width = 0.1 # 柱状图宽度
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='BUG总数量')
rects2 = ax.bar(x + width/2, women_means, width, label='严重BUG数量')
rects3 = ax.bar((x + width/2) + width, hui_gui, width, label='回归次数')
# 添加一些说明
ax.set_ylabel('数量')
ax.set_title('项目质量对比')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
def autolabel(rects):
"""在柱状图上打上数字进行显示."""
for rect in rects:
height = rect.get_height()
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
fig.tight_layout()
plt.show()