# -*- coding: utf-8 -*- # author:Li Mingjie time:2019/2/28 # Brief:Response time analysis import matplotlib.pyplot as plt import bottom_function.data_read as dr def cost_time_plot(datatype, starttime, endtime): cost_time_dict = dr.read_cost_time_data(datatype=datatype, starttime=starttime, endtime=endtime) y_max = 0 xl_list = list(cost_time_dict.keys()) fig = plt.figure(figsize=(10, 6)) for x in range(6): lab_list = [] y_list = [] x_list = [] t_list = list(cost_time_dict[xl_list[x]])[0:3] for m in t_list: lab_list.append(m[0]) y_list.append(m[1]) x += 0.2 x_list.append(x) y_max = max(y_list) if max(y_list) > y_max else y_max plt.bar(x_list, y_list, width=0.2, color=['r', 'g', 'b']) for i, j, lab in zip(x_list, y_list, lab_list): plt.text(i, j, lab, ha='center', va='bottom', fontsize=9, rotation=70) # plt.rcParams['font.family'] = ['sans-serif'] # plt.rcParams['font.sans-serif'] = ['SimHei'] # plt.xticks(np.arange(0.5,6,1),xl_list,position=(0.06,-0.07)) plt.ylim(0, y_max * 1.2) plt.xticks(np.arange(0.5, 6, 1), xl_list) if datatype == 'application': plt.title(str(starttime) + ' to ' + str(endtime) + ' cost time analysis of application resources', fontsize=12) elif datatype == 'control': plt.title(str(starttime) + ' to ' + str(endtime) + ' cost time analysis of control resources', fontsize=12) else: plt.title(str(starttime) + ' to ' + str(endtime) + ' cost time analysis of all resources', fontsize=12) plt.tight_layout(5) path = '/roobo/soft/phpmyadmin/response_time.jpg' plt.savefig(path) return path