AI智能
改变未来

Python数据可视化入门

##前言python可视化的模块是mtaplotlib,我们要使用它来生成统计图。

##示例

import matplotlib.pyplot as pltimport 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 offsettextcoords="offset points",ha=\'center\', va=\'bottom\')autolabel(rects1)autolabel(rects2)autolabel(rects3)fig.tight_layout()plt.show()

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » Python数据可视化入门