def netChart(ymNetPath, qqNetPath, xyNetPath): transLine = pyecharts.Line("游密、qq、小鱼性能对比", "transmit流量(KB)") recLine = pyecharts.Line("游密、qq、小鱼性能对比", "receive流量(KB)") ymTran, ymRec, ymbtran, ymbrec = netData(ymNetPath) qqTran, qqRec, qqbtran, qqbrec = netData(qqNetPath) xyTran, xyRec, xybtran, xybrec = netData(xyNetPath) transLine.add("游密", [x for x in range(len(ymTran))], ymTran, is_more_utils=True) # 标题 transLine.add("qq", [x for x in range(len(qqTran))], qqTran, is_more_utils=True) # 标题 transLine.add("小鱼", [x for x in range(len(xyTran))], xyTran, is_more_utils=True) # 标题 # transLine.show_config() # 展示HTML源代码 transLine.render("Net_trans.html") recLine.add("游密", [x for x in range(len(ymRec))], ymRec, is_more_utils=True) # 标题 recLine.add("qq", [x for x in range(len(qqRec))], qqRec, is_more_utils=True) # 标题 recLine.add("小鱼", [x for x in range(len(xyRec))], xyRec, is_more_utils=True) # 标题 # recLine.show_config() # 展示HTML源代码 recLine.render("Net_rec.html") btranLine = pyecharts.Line("游密、qq、小鱼性能对比", "上行带宽码率(KB/s)") brecLine = pyecharts.Line("游密、qq、小鱼性能对比", "下行带宽码率(KB/s)") btranLine.add("游密", [x for x in range(len(ymbtran))], ymbtran, is_more_utils=True) # 标题 btranLine.add("qq", [x for x in range(len(qqbtran))], qqbtran, is_more_utils=True) # 标题 btranLine.add("小鱼", [x for x in range(len(xybtran))], xybtran, is_more_utils=True) # 标题 # btranLine.show_config() # 展示HTML源代码 btranLine.render("br_trans.html") brecLine.add("游密", [x for x in range(len(ymbrec))], ymbrec, is_more_utils=True) # 标题 brecLine.add("qq", [x for x in range(len(qqbrec))], qqbrec, is_more_utils=True) # 标题 brecLine.add("小鱼", [x for x in range(len(xybrec))], xybrec, is_more_utils=True) # 标题 # brecLine.show_config() # 展示HTML源代码 brecLine.render("br_rec.html")
def year_line(): douban = pd.read_csv(os.getcwd() + "\douban_clean.csv") douban2 = douban['star'].groupby(douban['name']).count().to_frame() douban2 = douban2[douban2['star'] >= 5].reset_index() douban3 = pd.merge(douban2, douban, on='name') year_info = douban['name'].groupby(douban['year']).count() year_info2 = douban['people'].groupby(douban['year']).mean() year_info3 = douban['star'].groupby(douban['year']).mean() year_info = pd.DataFrame(year_info) year_info2 = pd.DataFrame(year_info2) year_info3 = pd.DataFrame(year_info3) year_all = pd.concat([year_info, year_info2, year_info3], axis=1) year_all.index = year_all.index.astype('str') year_all = year_all.round(2) print(year_all) line1 = py.Line(page_title="出版年份与出版数量折线图", width=1200) line1.add( "出版数量", year_all.index, year_all['name'], is_label_show=True, mark_point=["average", "max", "min"], mark_point_symbol="diamond", mark_point_textcolor="#40ff27", is_more_utils=True, ) line2 = py.Line(page_title="出版年份与评价平均人数折线图", width=1800) line2.add( "评价平均人数", year_all.index, year_all['people'], is_label_show=True, is_more_utils=True, ) line3 = py.Line(page_title="出版年份与评价平均数折线图", width=1800) line3.add( "评分平均数", year_all.index, year_all['star'], is_label_show=True, mark_point=["average", "max", "min"], mark_point_symbol="diamond", mark_point_textcolor="#40ff27", is_more_utils=True, ) line1.render("numByYear1.html") line2.render("numByYear2.html") line3.render("numByYear3.html")
def netChart(ymNetPath,agNetPath): transLine = pyecharts.Line("游密声网性能对比", "transmit流量(KB)") recLine = pyecharts.Line("游密声网性能对比", "receive流量(KB)") ymTran,ymRec= netData(ymNetPath) agTran,agRec = netData(agNetPath) transLine.add("游密", [x for x in range(len(ymTran))], ymTran, is_more_utils=True) # 标题 transLine.add("声网", [x for x in range(len(agTran))], agTran, is_more_utils=True) # 标题 transLine.show_config() # 展示HTML源代码 transLine.render("Net_trans.html") recLine.add("游密", [x for x in range(len(ymRec))], ymRec, is_more_utils=True) # 标题 recLine.add("声网", [x for x in range(len(agRec))], agRec, is_more_utils=True) # 标题 recLine.show_config() # 展示HTML源代码 recLine.render("Net_rec.html")
def pr_curve(y_true, y_pred, pos_label=1, jupyter=True, path='Precision Recall Curve.html'): t = pd.DataFrame({'prob': y_pred, 'label': y_true}) assert t.label.nunique() == 2, "`y_true` should be binary classification." label_dict = {i: 1 if i == pos_label else 0 for i in t.label.unique()} t['label'] = t.label.replace(label_dict) t = t.sort_values(['prob', 'label'], ascending=False).reset_index(drop=True) t['tp'] = t.label.cumsum() t['fp'] = t.index + 1 - t.tp t['recall'] = t.tp / t.label.sum() t['precision'] = t.tp / (t.tp + t.fp) line = pe.Line("PR Curve") line.add("PR", [0] + t.recall.round(4).tolist(), [1] + t.precision.round(4).tolist(), is_smooth=True, is_fill=True, area_opacity=0.4, yaxis_type='value', xaxis_type='value', xaxis_name='recall', yaxis_name='precision') return line if jupyter else line.render(path)
def roc_curve(y_true, y_pred, pos_label=1, jupyter=True, path='Receiver Operating Characteristic Curve.html'): t = pd.DataFrame({'prob': y_pred, 'label': y_true}) assert t.label.nunique() == 2, "`y_true` should be binary classification." label_dict = {i: 1 if i == pos_label else 0 for i in t.label.unique()} t['label'] = t.label.replace(label_dict) t = t.sort_values(['prob', 'label'], ascending=False).reset_index(drop=True) t['tp'] = t.label.cumsum() t['fp'] = t.index + 1 - t.tp t['tpr'] = t.tp / t.label.sum() t['fpr'] = t.fp / (t.label.count() - t.label.sum()) line = pe.Line("ROC Curve") line.add("ROC", [0] + t.fpr.round(4).tolist(), [0] + t.tpr.round(4).tolist(), is_smooth=True, is_fill=True, area_opacity=0.4, yaxis_type='value', xaxis_type='value') line.add("Random", [0] + t.fpr.round(4).tolist(), [0] + t.fpr.round(4).tolist(), yaxis_type='value', xaxis_type='value', xaxis_name='FPR', yaxis_name='TPR') return line if jupyter else line.render(path)
def gini_curve(y_true, y_pred, pos_label=1, jupyter=True, path='Gini Curve.html'): t = pd.DataFrame({'prob': y_pred, 'label': y_true}) assert t.label.nunique() == 2, "`y_true` should be binary classification." label_dict = {i: 1 if i == pos_label else 0 for i in t.label.unique()} t['label'] = t.label.replace(label_dict) t = t.sort_values(['prob', 'label']).reset_index(drop=True) t['cum'] = t.label.cumsum() / t.label.sum() t.index = np.round(((t.index + 1) / len(t)), 2) line = pe.Line("Gini Curve") line.add("Random", [0] + t.index.tolist(), [0] + t.index.tolist(), is_fill=True, area_opacity=0.4, is_smooth=True, yaxis_type='value', xaxis_type='value') line.add("Gini", [0] + t.index.tolist(), [0] + t.cum.round(4).tolist(), is_fill=True, area_opacity=0.4, is_smooth=True, yaxis_type='value', xaxis_type='value') return line if jupyter else line.render(path)
def ks_curve(y_true, y_pred, pos_label=1, jupyter=True, path='Kolmogorov-Smirnov Curve.html'): t = pd.DataFrame({'prob': y_pred, 'label': y_true}) assert t.label.nunique() == 2, "`y_true` should be binary classification." label_dict = {i: 1 if i == pos_label else 0 for i in t.label.unique()} t['label'] = t.label.replace(label_dict) t = t.sort_values(['prob', 'label'], ascending=False).reset_index(drop=True) t['tp'] = t.label.cumsum() t['fp'] = t.index + 1 - t.tp t['tpr'] = t.tp / t.label.sum() t['fpr'] = t.fp / (t.label.count() - t.label.sum()) t['ks'] = (t.tpr - t.fpr).abs().round(4) t.index = np.round(((t.index + 1) / len(t)), 2) line = pe.Line("Kolmogorov-Smirnov Curve") line.add("TPR", [0] + t.index.tolist(), [0] + t.tpr.round(4).tolist(), is_smooth=True, yaxis_type='value', xaxis_type='value') line.add("FPR", [0] + t.index.tolist(), [0] + t.fpr.round(4).tolist(), is_smooth=True, yaxis_type='value', xaxis_type='value') line.add("KS", [0] + t.index.tolist(), [0] + t.ks.tolist(), is_smooth=True, mark_point=["max"], yaxis_type='value', xaxis_type='value') return line if jupyter else line.render(path)
def plot_oil_price_(re_dic, to_path): dw = my_(config.MYSQL_BI_RW_ENV) sql1 = "select * from bi_papapa.city_oil_price where origin='%(origin)s' and province='%(region)s' group by offer_date,oil_number order by offer_date desc limit 400; " % re_dic data2 = dw.to_dataframe(sql1) data2 = data2[::-1] # data2['offer_date'] = pd.DatetimeIndex(data2['offer_date']).strftime('%Y-%m-%d') # offer_date=pd.DatetimeIndex(data2['offer_date']).strftime('%Y-%m-%d') # func = lambda x, y: x if y in x else x + [y] price_min = data2['price'].min() offer_date = data2.loc[data2['offer_date'].duplicated() == False, ['offer_date', 'price']] oil_number_0 = data2[data2['oil_number'] == '0'][['offer_date', 'price']] # data2.query('oil_number=0')[['offer_date', 'price']] oil_number_89 = data2[data2['oil_number'] == '89'][['offer_date', 'price']] oil_number_92 = data2[data2['oil_number'] == '92'][['offer_date', 'price']] oil_number_95 = data2[data2['oil_number'] == '95'][['offer_date', 'price']] oil_number_98 = data2[data2['oil_number'] == '98'][['offer_date', 'price']] dfr = offer_date.merge(oil_number_0, how='left', on='offer_date', suffixes=['','_0'])\ .merge(oil_number_89, how='left', on='offer_date', suffixes=['','_89'])\ .merge(oil_number_92, how='left', on='offer_date', suffixes=['','_92'])\ .merge(oil_number_95, how='left', on='offer_date', suffixes=['','_95'])\ .merge(oil_number_98, how='left', on='offer_date', suffixes=['', '_98']) line = pyecharts.Line(re_dic['region'], "油价趋势:"+re_dic['origin'], width=1400, height=700) tem_dic = dict(label_text_size=12, is_label_show=True, is_fill=True, area_opacity=0.12, line_width=2, is_smooth=True, mark_point=["average"], yaxis_min=price_min) line.add("0号柴油", dfr['offer_date'], dfr['price_0'], **tem_dic) line.add("89号汽油", dfr['offer_date'], dfr['price_89'], **tem_dic) line.add("92号汽油", dfr['offer_date'], dfr['price_92'], **tem_dic) line.add("95号汽油", dfr['offer_date'], dfr['price_95'], **tem_dic) line.add("98号汽油", dfr['offer_date'], dfr['price_98'], **tem_dic) line.render(to_path)
def plot_more_line(data,name,title,x_roate = 0,y_roate = 0): """ 绘制多条折现 :param data: :param name: :param title: :param x_roate: :param y_roate: :return: """ stackBar = pyecharts.Line(title) label = [] legend = ['max','min','ave','most'] maxSizes = [] minSizes = [] aveSizes = [] mostSizes = [] for row in data: label.append(row[0]) maxSizes.append(row[1]['max']) minSizes.append(row[1]['min']) aveSizes.append(row[1]['ave']) mostSizes.append(row[1]['most']) stackBar.add(legend[1],label,minSizes,) stackBar.add(legend[2],label,aveSizes,) stackBar.add(legend[3],label,mostSizes,mark_line=["average"]) stackBar.add(legend[0],label,maxSizes,is_datazoom_show=True,is_smooth=True,xaxis_interval=0,xaxis_rotate=x_roate, yaxis_rotate=y_roate) stackBar.render('templates/{}.html'.format(name))
def read_csv(): pddata = pd.read_csv('/Users/ludanqing/Desktop/test3.csv') # 返回全部列名 # cols = pddata.columns # print(pddata['日期'][1]) bar = pyecharts.Line("一周访问量", "千里眼") time = pddata['日期'] today = pddata['数据1'] yesterday = pddata['数据2'] # time = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] # today = [5, 20, 36, 10, 75, 90, 28] # yesterday = [25, 10, 56, 70, 25, 40, 88] bar.add("这周", time, today, mark_point=["max", "min"], mark_line=["average"], is_more_utils=True) bar.add("上周", time, yesterday, mark_point=["max", "min"], mark_line=["average"], is_more_utils=True) return bar
def create_chart(): g_r, result = get_data() result[0] = 0 line = pyecharts.Line(str1, strTime) line.add(str1, g_r, result, is_label_show=True) #line.add("最低气温", cities, lows, mark_line=['average'], is_smooth=True) line.render('hezhi.png')
def visual_histo_pye(self, savePath): names = self.data[0][:self.TOP] boxfiles = self.data[1][:self.TOP] bar = pye.Bar('TOP{} Films in {}'.format(self.TOP, self.YEAR), width=1080, height=640) bar.add("bar", names, boxfiles, yaxis_formatter=" M$", is_toolbox_show=False, xaxis_rotate=15) line = pye.Line(width=1080, height=640) line.add('line', names, boxfiles, is_toolbox_show=False, xaxis_rotate=15) overlap = pye.Overlap('TOP{} Films in {}'.format(self.TOP, self.YEAR), width=1080, height=640) overlap.add(bar) overlap.add(line) overlap.render(savePath)
def click2(self): conn = pymysql.connect(host='localhost', user='******', password='******', port=3306, db='maoyan', charset='utf8mb4') sql = "select * from films" db = pd.read_sql(sql, conn) y = [([0] * 13) for i in range(4)] t1 = threading.Thread(target=self.myshow) t2 = threading.Thread(target=self.mytr) for i in range(2015, 2019, 1): for j in range(1, 13, 1): y[i - 2015][j] = db[(db.year == i) & (db.month == j)].sum()["box_office"] x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] y1 = y[0] y2 = y[1] y3 = y[2] y4 = y[3] line = pyecharts.Line("2015 to 2018", width=1200, height=500) line.add("2015", x, y1) line.add("2016", x, y2) line.add("2017", x, y3) line.add("2018", x, y4) line.render("2015_to_2018.html") self.widget.load(QUrl('file:///2015_to_2018.html')) t1.start() t2.start()
def lift_curve(y_true, y_pred, pos_label=1, jupyter=True, path='Lift Curve.html'): t = pd.DataFrame({'prob': y_pred, 'label': y_true}) assert t.label.nunique() == 2, "`y_true` should be binary classification." label_dict = {i: 1 if i == pos_label else 0 for i in t.label.unique()} t['label'] = t.label.replace(label_dict) t = t.sort_values(['prob', 'label'], ascending=False).reset_index(drop=True) t['tp'] = t.label.cumsum() t['fp'] = t.index + 1 - t.tp t['precision'] = t.tp / (t.tp + t.fp) t['lift'] = t.precision / t.label.sum() * t.label.count() t.index = np.round(((t.index + 1) / len(t)), 2) line = pe.Line("Lift Curve") line.add("Lift", t.index.tolist(), t.lift.round(3).tolist(), is_smooth=True, yaxis_type='value', xaxis_type='value') line.add("Random", t.index.tolist(), [1] * len(t), is_smooth=True, yaxis_type='value', xaxis_type='value') return line if jupyter else line.render(path)
def plot_fill_line(data,name,title): label = [i[0] for i in data] lengend = ['0-10','10-20','20-30','30-40','40-50', '50-60','60-70','70-80','80-90','90-100','>100'] size_0 = [i[1]['0-10'] for i in data] size_1 = [i[1]['10-20'] for i in data] size_2 = [i[1]['20-30'] for i in data] size_3 = [i[1]['30-40'] for i in data] size_4 = [i[1]['40-50'] for i in data] size_5 = [i[1]['50-60'] for i in data] size_6 = [i[1]['60-70'] for i in data] size_7 = [i[1]['70-80'] for i in data] size_8 = [i[1]['80-90'] for i in data] size_9 = [i[1]['90-100'] for i in data] size_10 = [i[1]['>100'] for i in data] fillLine = pyecharts.Line(title) fillLine.add(lengend[0],label,size_0,is_smooth=True,is_fill=True) fillLine.add(lengend[1],label,size_1,is_smooth=True,is_fill=True) fillLine.add(lengend[2],label,size_2,is_smooth=True,is_fill=True) fillLine.add(lengend[3],label,size_3,is_smooth=True,is_fill=True) fillLine.add(lengend[4],label,size_4,is_smooth=True,is_fill=True) fillLine.add(lengend[5],label,size_5,is_smooth=True,is_fill=True) fillLine.add(lengend[6],label,size_6,is_smooth=True,is_fill=True) fillLine.add(lengend[7],label,size_7,is_smooth=True,is_fill=True) fillLine.add(lengend[8],label,size_8,is_smooth=True,is_fill=True) fillLine.add(lengend[9],label,size_9,is_smooth=True,is_fill=True) fillLine.add(lengend[10],label,size_10,is_smooth=True,is_fill=True) fillLine.render('templates/{}.html'.format(name))
def plot_station_lostavg(re_dic, to_path): re_dic = add_whereadd_redic(re_dic) dic_station, dic_smarttime = get_station_detail_(re_dic) re_dic['stname'] = '%s-%s' % (dic_station['city'], dic_station['stname']) dw = my_(config.MYSQL_BI_RW_ENV) sql_mer = """SELECT sum(if(spr_id<3,value_c,0)) users_7,sum(if(spr_id<4,value_c,0)) users_15,sum(value_c*value_e) lostday_a,sum(value_c) users_a,batch_date FROM profile.pr_stations_user_dis_ where mer_id = %(mer_id)s and tar_id = 30 %(whereadd)s group by batch_date""" % re_dic sql_all = """SELECT sum(if(spr_id<3,value_c,0)) users_7,sum(if(spr_id<4,value_c,0)) users_15,sum(value_c*value_e) lostday_a,sum(value_c) users_a,batch_date FROM profile.pr_platforms_user_dis_ where mer_id = 0 and tar_id = 30 %(whereadd)s group by batch_date""" % re_dic data_mer = dw.to_dataframe(sql_mer) data_all = dw.to_dataframe(sql_all) page = pyecharts.Page(page_title='流失分析',) X = data_all['batch_date'] tem_dic = dict(label_text_size=12, is_label_show=False, is_fill=True, area_opacity=0.08, line_width=2, is_smooth=True, mark_line=["average"] , xaxis_interval=1, xaxis_rotate=45) line1 = pyecharts.Line("平均流失天数趋势:", "%(stname)s(%(mer_id)s)" % re_dic, width=1500, height=600) lostavg_mer = (data_mer['lostday_a'] / data_mer['users_a']).round(2) lostavg_all = (data_all['lostday_a'] / data_all['users_a']).round(2) line1.add("油站", X, lostavg_mer, **tem_dic) line1.add("全平台", X, lostavg_all, **tem_dic) page.add(line1) rrate_mer = (data_mer['users_15'] / data_mer['users_a']).round(4) rrate_all = (data_all['users_15'] / data_all['users_a']).round(4) line2 = pyecharts.Line("流失15日内的用户占比:", "%(stname)s(%(mer_id)s)" % re_dic, width=1500, height=600) conb_ = np.append(rrate_mer, rrate_all) tem_dic.update({'yaxis_min': conb_.min() * 0.6}) lineadd_sted(line2, dic_smarttime, X, conb_.max() * 1.2) line2.add("油站", X, rrate_mer, **tem_dic) line2.add("全平台", X, rrate_all, **tem_dic) page.add(line2) rrate_mer = (data_mer['users_7'] / data_mer['users_a']).round(4) rrate_all = (data_all['users_7'] / data_all['users_a']).round(4) line2 = pyecharts.Line("流失7日内的用户占比:", "%(stname)s(%(mer_id)s)" % re_dic, width=1500, height=600) conb_ = np.append(rrate_mer, rrate_all) tem_dic.update({'yaxis_min': conb_.min() * 0.6}) lineadd_sted(line2, dic_smarttime, X, conb_.max() * 1.2) line2.add("油站", X, rrate_mer, **tem_dic) line2.add("全平台", X, rrate_all, **tem_dic) page.add(line2) page.render(to_path)
def cpuChart(ymCpuPath,agCpuPath): cpuLine = pyecharts.Line("游密声网性能对比", "cpu(%)") ymCpu = cpuData(ymCpuPath) agCpu = cpuData(agCpuPath) cpuLine.add("游密", [x for x in range(len(ymCpu))], ymCpu, is_more_utils=True) # 标题 cpuLine.add("声网", [x for x in range(len(agCpu))], agCpu, is_more_utils=True) # 标题 cpuLine.show_config() # 展示HTML源代码 cpuLine.render("cpu.html")
def memChart(ymMemPath,agMemPath): memLine = pyecharts.Line("游密声网性能对比", "内存(Mb)") ymMem = memData(ymMemPath) agMem = memData(agMemPath) memLine.add("游密", [x for x in range(len(ymMem))], ymMem, is_more_utils=True) # 标题 memLine.add("声网", [x for x in range(len(agMem))], agMem, is_more_utils=True) # 标题 memLine.show_config() # 展示HTML源代码 memLine.render("mem.html")
def create_Line(): line = pyecharts.Line("气温变化折线图", '2018-4-16', width=1200, height=600) line.add("最高气温", cities, highs, mark_point=['average'], is_datazoom_show=True) line.add("最低气温", cities, lows, mark_line=['average'], is_smooth=True) # line.render('Line-High-Low.html') page.add(line)
def test_add(*args, **kwargs): line = pe.Line('Test Line add ' + kwargs.get('data_type', '')) line.add(*args) line.show_config() line.render('./test_line_add_{}.html'.format(kwargs.get('data_type', ''))) bar = pe.Bar('Test Bar add ' + kwargs.get('data_type', '')) bar.add(*args) bar.show_config() bar.render('./test_bar_add_{}.html'.format(kwargs.get('data_type', '')))
def test_add_df(df): line = pe.Line('Test Line add_df') line.add_df(df) line.show_config() line.render('./test_line_add_df.html') bar = pe.Bar('Test Bar add_df') bar.add_df(df) bar.show_config() bar.render('./test_bar_add_df.html')
def volChart(ymVolPath,agVolPath): volLine = pyecharts.Line("游密声网性能对比", "电压(V)") ymVol = volData(ymVolPath) agVol = volData(agVolPath) print(ymVol) print(agVol) volLine.add("游密", [x for x in range(len(ymVol))], ymVol, is_more_utils=True) # 标题 volLine.add("声网", [x for x in range(len(agVol))], agVol, is_more_utils=True) # 标题 volLine.show_config() # 展示HTML源代码 volLine.render("vol.html")
def curChart(ymCurPath,agCurPath): curLine = pyecharts.Line("游密声网性能对比", "电流(mA)") ymCur = curData(ymCurPath) agCur = curData(agCurPath) print(ymCur) print(agCur) curLine.add("游密", [x for x in range(len(ymCur))], ymCur, is_more_utils=True) # 标题 curLine.add("声网", [x for x in range(len(agCur))], agCur, is_more_utils=True) # 标题 curLine.show_config() # 展示HTML源代码 curLine.render("cur.html")
def visual_histo_pye(self, savePath): names = list(self.data.keys())[-self.TOP:] joinFilms = list(self.data.values())[-self.TOP:] bar = pye.Bar(width=1080, height=640) bar.add("bar", names, joinFilms, is_toolbox_show=False) line = pye.Line(width=1080, height=640) line.add('line', names, joinFilms, is_toolbox_show=False) overlap = pye.Overlap('TOP{} Actors in {}'.format(self.TOP, self.YEAR), 'sorted by JoinFilms') overlap.add(bar) overlap.add(line) overlap.render(savePath)
def visual_line_pye(self, data, savePath): _xticks_labels = ['spring', 'summer', 'fall', 'winter'] line = pye.Line("Boxfile Change Trend by seasons", 'in Millions', width=1080, height=640) for YEAR in self.years: y = data[YEAR] line.add('Year' + str(YEAR), _xticks_labels, y, is_toolbox_show=False) line.render(savePath)
def construct_graph(self, x_kv, y_kv, x_label_name): """ construct graph (x axis is the thread count) :param x_kv: :param y_kv: :param x_label_name: :return: """ lines = {} for x_value in x_kv.values(): db_type = x_value.get(self.db_type_key) if lines.get(db_type) is None: lines.setdefault(db_type, []) x_tmp_list = [] for k, x_value in x_kv.items(): y_value = y_kv.get(k) db_type = x_value.get(self.db_type_key) x, y = x_value.get(x_label_name), y_value.get(self.ops_key) x_tmp_list.append(x) li = lines.get(db_type) li += [(x, y)] lines.update({db_type: li}) # sort by x value for k in lines.keys(): lines.update({k: sorted(lines.get(k), key=lambda item: item[0])}) # Now every line could construct the single line in the graph # Every line denotes the target DB type workload_map = read_workload() title = x_value[self.workload_key].title() sub_title = workload_map[x_value[self.workload_key]] if x_value[self.workload_key] in workload_map else '' line = pyecharts.Line(title, sub_title, height=300, title_text_size=14, subtitle_text_size=10, title_pos='center') # https://pyecharts.readthedocs.io/en/latest/zh-cn/%E5%9B%BE%E5%BD%A2%E7%AF%87/ for label, v in lines.items(): X, y = [str(item[0]) for item in v], [item[1] for item in v] line.add(label, X, y, xaxis_name=' '.join(x_label_name.split('_')), yaxis_name=self.ops_key, xaxis_name_pos='middle', yaxis_name_pos='end', legend_pos='right', legend_orient='vertical' ) return line
def curChart(ymCurPath, qqCurPath, xyCurPath): curLine = pyecharts.Line("游密、qq、小鱼性能对比", "电流(mA)") ymCur = curData(ymCurPath) qqCur = curData(qqCurPath) xyCur = curData(xyCurPath) curLine.add("游密", [x for x in range(len(ymCur))], ymCur, is_more_utils=True) # 标题 curLine.add("qq", [x for x in range(len(qqCur))], qqCur, is_more_utils=True) # 标题 curLine.add("xy", [x for x in range(len(xyCur))], xyCur, is_more_utils=True) # 标题 # curLine.show_config() # 展示HTML源代码 curLine.render("cur.html")
def memChart(ymMemPath, qqMemPath, xyMemPath): memLine = pyecharts.Line("游密、qq、小鱼性能对比", "内存(MB)") ymMem = memData(ymMemPath) qqMem = memData(qqMemPath) xyMem = memData(xyMemPath) memLine.add("游密", [x for x in range(len(ymMem))], ymMem, is_more_utils=True) # 标题 memLine.add("qq", [x for x in range(len(qqMem))], qqMem, is_more_utils=True) # 标题 memLine.add("小鱼", [x for x in range(len(xyMem))], xyMem, is_more_utils=True) # 标题 # memLine.show_config() # 展示HTML源代码 memLine.render("mem.html")
def cpuChart(ymCpuPath, qqCpuPath, xyCpuPath): cpuLine = pyecharts.Line("游密、qq、小鱼性能对比", "cpu(%)") ymCpu = cpuData(ymCpuPath) qqCpu = cpuData(qqCpuPath) xyCpu = cpuData(xyCpuPath) cpuLine.add("游密", [x for x in range(len(ymCpu))], ymCpu, is_more_utils=True) # 标题 cpuLine.add("qq", [x for x in range(len(qqCpu))], qqCpu, is_more_utils=True) # 标题 cpuLine.add("小鱼", [x for x in range(len(xyCpu))], xyCpu, is_more_utils=True) # 标题 # cpuLine.show_config() # 展示HTML源代码 cpuLine.render("cpu.html")
def volChart(ymVolPath, qqVolPath, xyVolPath): volLine = pyecharts.Line("游密、qq、小鱼性能对比", "电压(V)") ymVol = volData(ymVolPath) qqVol = volData(qqVolPath) xyVol = volData(xyVolPath) volLine.add("游密", [x for x in range(len(ymVol))], ymVol, is_more_utils=True) # 标题 volLine.add("qq", [x for x in range(len(qqVol))], qqVol, is_more_utils=True) # 标题 volLine.add("小鱼", [x for x in range(len(xyVol))], xyVol, is_more_utils=True) # 标题 # volLine.show_config() # 展示HTML源代码 volLine.render("vol.html")