def plot_geo_station_num(re_dic, to_path): dw = my_(config.MYSQL_BI_RW_ENV) muchcols_table = 'data_center.dc_stations_muchcols_enc' sqls = "select city scale,avg(latitude) avg_lat,avg(longitude) avg_lng,count(*) numbers from %s where name like '%%%s%%' group by city order by numbers desc" % ( muchcols_table, re_dic['name']) count_station_ = dw.to_dataframe(sqls) # count_station_['scale'] = count_station_['scale'].apply(lambda x: change_city(x, pro)) coords = {} for i in range(len(count_station_)): coords[count_station_.loc[i, 'scale']] = [count_station_.loc[i, 'avg_lng'], count_station_.loc[i, 'avg_lat']] num_Max = count_station_['numbers'].max() name_str = "油站名包含'%s':" % re_dic['name'] if re_dic['name'] else '' page = pyecharts.Page() style = pyecharts.Style(width=1300, height=860, background_color='#404a66', title_color="#eee", title_pos="center") geo = pyecharts.Geo(name_str + "油站分布地图", **style.init_style) geo.add("", count_station_['scale'], count_station_['numbers'], visual_text_color="#eee", is_legend_show=False, symbol_size=12, is_visualmap=True, visual_range=[0, num_Max], tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right', geo_cities_coords=coords) page.add(geo) chart2 = pyecharts.Bar(name_str + "油站分布柱状图", **style.init_style) chart2.add("", count_station_['scale'][:25], count_station_['numbers'][:25], visual_range=[0, num_Max], is_label_show=True, is_visualmap=True, visual_text_color='#eee') page.add(chart2) page.render(to_path)
def plot_oil_station_num_(re_dic, to_path): standard_province = ['安徽', '贵州', '澳门', '北京', '重庆', '福建', '福建', '甘肃', '广东', '广西', '广州', '海南', '河北', '黑龙江', '河南', '湖北', '湖南', '江苏', '江西', '吉林', '辽宁', '内蒙古', '宁夏', '青海', '山东', '上海', '陕西', '山西', '四川', '台湾', '天津', '香港', '新疆', '西藏', '云南', '浙江'] dw = my_(config.MYSQL_BI_RW_ENV) muchcols_table = 'data_center.dc_stations_muchcols_enc' if re_dic['scale'] == 'china': sqls = "select province scale,count(*) numbers from %s where name like '%%%s%%' group by province order by numbers desc" % (muchcols_table, re_dic['name']) count_station_ = dw.to_dataframe(sqls) count_station_['scale'] = count_station_['scale'].apply(lambda x: change_city(x, standard_province)) else: re_dic['scale'] = re_dic['scale'].split('省')[0] re_dic['scale'] = re_dic['scale'].split('市')[0] sqls = "select city scale,count(*) numbers from %s where province like '%%%s%%' and name like '%%%s%%' group by city order by numbers desc" % (muchcols_table, re_dic['scale'], re_dic['name']) count_station_ = dw.to_dataframe(sqls) num_Max = count_station_['numbers'].max() name_str = "油站名包含'%s':" %re_dic['name'] if re_dic['name'] else '' page = pyecharts.Page() style = pyecharts.Style(width=1300, height=860, background_color='#606a79', title_color="#eee", title_pos="center") map1 = pyecharts.Map(name_str+"油站分布地图", **style.init_style) map1.add("", count_station_['scale'], count_station_['numbers'], maptype=re_dic['scale'], visual_range=[0, num_Max], is_label_show=True, is_visualmap=True, visual_text_color='#eee') page.add(map1) chart2 = pyecharts.Bar(name_str+"油站分布柱状图", **style.init_style) chart2.add("", count_station_['scale'][:25], count_station_['numbers'][:25], maptype=re_dic['scale'], visual_range=[0, num_Max], is_label_show=True, is_visualmap=True, visual_text_color='#eee') page.add(chart2) page.render(to_path)
def func(): page = pyecharts.Page() # step 1 # bar attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = pyecharts.Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) page.add(bar) # step 2 # scatter3D import random data = [[ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] for _ in range(80)] range_color = [ '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026' ] scatter3D = pyecharts.Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) page.add(scatter3D) # step 2 page.render() # step 3 # scatter_geo attr = ['11', '22'] data = ['1', '2'] scatter_geo = pyecharts.Geo("地理位置视图", width=1200, height=600) scatter_geo.add("", attr, data) page.add(scatter_geo) # step 2 page.render() # step 3 data = [["广州", "北京"], ["广州", "上海"]] scatter_geo = pyecharts.GeoLines("地理位置视图", width=1200, height=600) scatter_geo.add("上午航班", data, geo_normal_color='#ff00ff', geo_effect_period=9, geo_effect_color='#ff0000', geo_effect_symbol='arrow') data = [["广州", "南昌"], ["广州", "成都"]] scatter_geo.add("下午航班", data, geo_effect_traillength=1, geo_emphasis_color='#0000ff') page.add(scatter_geo) # step 2 page.render() # step 3
def read_1688_all(cid, cat_name): page = pyecharts.Page() # 实例化page类 bar = read_1688_index(cid, cat_name) page.add(bar) attr_list = mongo_client2.get_1688attr(cid) # attrs = [] # for attr in attr_list: # attrs.append(attr) rows_by_type = defaultdict(list) for attr in attr_list: rows_by_type[attr['attr_type']].append(attr) for attr_type in rows_by_type.items(): # print(attr_type[1]['attr_value']) attr_value_index_group = [] attr_value_group = [] for attr in attr_type[1]: attr_value_index_group.append(attr['attr_value_index']) attr_value_group.append(attr['attr_value']) # print(attr_type[0]+"\t"+attr['attr_value']) # attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] # v1 = [11, 12, 13, 10, 10, 10] pie = pyecharts.Pie(attr_type[0], title_pos='50%') pie.add(attr_type[0], attr_value_group, attr_value_index_group, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') page.add(pie) # print(rows_by_type) # pie # attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] # v1 = [11, 12, 13, 10, 10, 10] # pie = Pie("饼图-圆环图示例", title_pos='50%') # pie.add("", attr, v1, radius=[40, 75], label_text_color=None, # is_label_show=True, legend_orient='vertical', legend_pos='left') # TODO 配置Grid类 # grid = Grid(height=720, width=1200) # 初始化,参数可传page_title,width,height # grid.add(bar, grid_bottom="60%", grid_left="60%") # 添加要展示的图表,并设置显示位置 # # grid.add(line, grid_bottom="60%", grid_right="60%") # 添加要展示的图表,并设置显示位置 # grid.add(pie, grid_bottom="60%", grid_right="60%") # grid.add(scatter, grid_top="60%", grid_left="60%") # 添加要展示的图表,并设置显示位置 # grid.add(es, grid_top="60%", grid_right="60%") # 添加要展示的图表,并设置显示位置 # grid.render("Grid_并行显示多张图表.html") # return grid return page
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 create_bar(): user_list = JobsInfo.objects.all().values_list("job_title", "job_salary", "job_exp") page = pe.Page() name = ["服装"] name2 = ["电器"] x = list(user_list[0]) y = ["50", 200, 100] y2 = ["50", 300, 1400] # bar bar = pe.Bar("我的第一个图表", "这里是副标题", width=600, height=300) bar.add(name, x, y) bar.add(name2, x, y2) page.add(bar) # line line = pe.Line('Demo Line', "这里是副标题", width=600, height=300) line.add(name, x, y) line.add(name2, x, y2) page.add(line) return page
def plot_geo_station(re_dic, to_path): dw = my_(config.MYSQL_BI_RW_ENV) muchcols_table = 'data_center.dc_stations_muchcols_enc' sqls = "select name scale,latitude lat,longitude lng from %s where name like '%%%s%%'" % (muchcols_table, re_dic['name']) count_station_ = dw.to_dataframe(sqls) count_station_['numbers']=1 coords={} for i in range(len(count_station_)): coords[count_station_.loc[i,'scale']]=[count_station_.loc[i,'lng'],count_station_.loc[i,'lat']] # num_Max = count_station_['numbers'].max() name_str = "油站名包含'%s':" %re_dic['name'] if re_dic['name'] else '' page = pyecharts.Page() style = pyecharts.Style(width=1300, height=860, background_color='#404a49', title_color="#eee", title_pos="center") geo = pyecharts.Geo(name_str+"油站分布地图",**style.init_style) geo.add("",count_station_['scale'], count_station_['numbers'], visual_text_color="#eee", is_legend_show=False, symbol_size=11, is_visualmap=True, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right',geo_cities_coords=coords) page.add(geo) page.render(to_path)
def Top10Holder(codenumber, startdate='2014-10-10'): """ Top10 holde 是将top10 股东用Pie 图进行可视化,其中包含一年股东变化的河流图. Parameters ---------- codenumber: stock 代码 startdate='2014-10-10': 起始时间 Returns ------- 输出为 当前文件夹下 html :top10.html """ if len(codenumber) != 6: #检查 code 长度 不符合6位全部错误 return False elif len(codenumber) == 6: datestr = startdate.split("-") thisyear = datestr[0] df2 = ts.top10_holders(code=codenumber, gdtype="1") # 下载数据 test = df2[1]["quarter"].tolist() #获取季度列表 df_ready = df2[1] idxlist = [] for idx, val in enumerate(test): a = val.split("-") if a[0] == thisyear: # print a[0],idx idxlist.append(idx) elif a[0] > thisyear: idxlist.append(idx) thing = df_ready.loc[idxlist] thing = pd.DataFrame(thing) thing = thing.sort_values(["quarter", "name"]) #排序所有流通股股东 quarterlist = thing.quarter.value_counts() quarterlist = quarterlist.index.sort_values() timeline = Timeline( height=600, width=800, timeline_left=20, timeline_right=100, is_auto_play=False, timeline_bottom=0, timeline_symbol='diamond', ) year_index = thing.quarter.apply( lambda x: x[0:4]) # year list ('20xx') yearlist = year_index.value_counts() yearlist = yearlist.index.sort_values() #print(quarterlist,year) for quarters in list(quarterlist): # 将每个季度画成PIE 加入TIMELINE df = thing[thing["quarter"] == quarters] df.h_pro = df.h_pro.apply(lambda x: float(x)) df.hold = df.hold.apply(lambda x: float(x)) sum_pro = round(df.h_pro.sum(), 2) sum_hold = round(np.mean(df.hold / df.h_pro) * sum_pro, 0) s = pd.Series({ 'name': '其他', 'h_pro': 100 - sum_pro, 'hold': sum_hold }) df = df.append(s, ignore_index=True) #df=df.sort_values(["name"]) pie = Pie('%s' % quarters + "-" + "top10holder", title_pos='outside') TopPie = pie.add( '', df.name, df.hold, radius=[20, 45], center=[45, 50], is_legend_show=True, is_label_show=True, # is_visualmap=True, is_more_utils=True, is_toolbox_show=True, legend_pos='left', legend_orient='vertical', legend_top=25, legend_text_size=12, label_text_size=10, label_text_color="#100", tooltip_text_color="#F0F", #is_label_emphasis=False,#是否显示高亮 label_formatter="{b}:\n {c}万股\n{d}%") #gird= Grid() #gird.add(pie,grid_bottom="20%") #gird.add(tab,grid_bottom="60%") #pietimeline.add(pie, quarters,) timeline.add( pie, quarters, ) #page = pyecharts.Page() #page.add(pie) #page.add(_treemap) #timeline.add(pie,quarters,) #timeline.add(_treemap,quarters,) #pietimeline.top('40%') trmtimeline = Timeline( height=1200, width=800, timeline_left=20, timeline_right=100, is_auto_play=False, timeline_bottom=0, timeline_symbol='diamond', ) #for y in list(yearlist): datas_index = [] for i, _year in enumerate(year_index): #获取datas_index if _year in list(yearlist)[-1:]: datas_index.append(i) else: pass print(thing.loc[datas_index, :]) collect_datas = thing.iloc[datas_index, :3] collect_datas.hold = collect_datas.hold.apply(lambda x: float(x)) print(collect_datas) name = collect_datas['name'] collect_datas.drop(labels=['name'], axis=1, inplace=True) collect_datas.insert(2, 'name', name) print(collect_datas.get_values()) tr = pyecharts.ThemeRiver( "TOP 10 hold 河流图 ", height=800, width=800, ) tr.add(name.get_values(), collect_datas.get_values(), is_label_show=False) #trmtimeline.add(tr,"%s"%y,) page = pyecharts.Page() # page.add(trmtimeline) page.add(timeline) page.add(tr) ''' them_dates=[] for i in thing.index: print (i) collect_datas=thing[thing.index==i].iloc[:, 0:3] name=collect_datas['name'] collect_datas.drop(labels=['name'], axis=1,inplace = True) collect_datas.insert(2, 'name', name) print (collect_datas.get_values()) ''' print('time line done') return page
def plot_monitor(dic_psi, dic_ks, dic_stats, cols=None, path='reportsource/model_monitor.html'): if not os.path.exists(os.path.dirname(os.path.abspath(path))): os.makedirs(os.path.dirname(os.path.abspath(path))) page = pyecharts.Page() for k in dic_psi.keys(): temp = pd.read_json(json.dumps(dic_psi[k], cls=MyEncoder)).sort_values('date') temp = temp[temp.volume > 100] line = pyecharts.Line(k + ' PSI监控') line.add('psi', temp.date, temp['psi'], xaxis_rotate=45, is_datazoom_show=True, tooltip_tragger='axis', datazoom_type='both', legend_pos='center', legend_orient='horizontal') line_pass = pyecharts.Line() line_pass.add('pass_ratio', temp.date, temp['pass_ratio'], xaxis_rotate=45, is_datazoom_show=True, tooltip_tragger='axis', datazoom_type='both', legend_pos='center', legend_orient='horizontal') bar = pyecharts.Bar() bar.add('volume', temp.date, temp['volume'], xaxis_rotate=45, is_datazoom_show=True, tooltip_tragger='axis', datazoom_type='both', legend_pos='center', legend_orient='horizontal') overlap = pyecharts.Overlap() overlap.add(line) overlap.add(line_pass) overlap.add(bar, yaxis_index=1, is_add_yaxis=True) page.add(overlap) for k in dic_ks.keys(): line = pyecharts.Line('%s features ks monitor' % k) for f in dic_ks[k].keys(): temp = pd.read_json(json.dumps(dic_ks[k][f], cls=MyEncoder)) temp = temp[temp['volume'] > 100] line.add(f, temp.date, temp.ks, xaxis_rotate=90, is_datazoom_show=True, tooltip_tragger='axis', datazoom_type='both', legend_pos='right', legend_orient='vertical') page.add(line) for k in dic_stats.keys(): if cols is None: cols_f = dic_stats[k].keys() else: cols_f = [f for f in cols if f in dic_stats[k].keys()] for f in cols_f: line = pyecharts.Line('%s features stats monitor: ' % k + f) temp = pd.DataFrame(dic_stats[k][f]).sort_values('date') stats_name = temp.iloc[0]['tr_v'].keys() for n in stats_name: temp_te_v = temp.te_v.apply(pd.Series) temp_tr_v = temp.tr_v.apply(pd.Series) line.add(n, temp.date, temp_te_v[n], is_datazoom_show=True, tooltip_tragger='axis', datazoom_type='both', legend_pos='right', legend_orient='vertical') line.add(n + '_benchmark', temp.date, temp_tr_v[n], is_datazoom_show=True, tooltip_tragger='axis', datazoom_type='both', legend_pos='right', legend_orient='vertical') page.add(line) page.render(path) return None
overlap = echarts.Overlap(width=1200, height=600) # 默认不新增 x y 轴,并且 x y 轴的索引都为 0 overlap.add(bar) # 新增一个 y 轴,此时 y 轴的数量为 2,第二个 y 轴的索引为 1(索引从 0 开始),所以设置 yaxis_index = 1 # 由于使用的是同一个 x 轴,所以 x 轴部分不用做出改变 overlap.add(line, yaxis_index=1, is_add_yaxis=True) overlap.render(path='tmp/overlap.html') # Page:同一网页按顺序展示多图 if __name__ == '__main__': import pyecharts as echarts # 示例 if __name__ == '__main__': page = echarts.Page() # step 1 # bar attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = echarts.Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) page.add(bar) # step 2 # scatter3D import random data = [ [random.randint(0, 100),
def plot_station_3ntends(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']) mapp = {'30':'250', '14':'251', '7':'252', 'dyn':'253'} re_dic['tar_id'] = mapp[re_dic['N']] dw = my_(config.MYSQL_BI_RW_ENV) sql_mer = "SELECT * FROM profile.pr_stations_user_dis2_ where mer_id = %(mer_id)s and tar_id = %(tar_id)s %(whereadd)s" % re_dic sql_all = "SELECT * FROM profile.pr_platforms_user_dis2_ where mer_id = 0 and tar_id = %(tar_id)s %(whereadd)s" % re_dic data_mer = dw.to_dataframe(sql_mer) data_all = dw.to_dataframe(sql_all) page = pyecharts.Page(page_title='3N分析',) tem_dic = dict(label_text_size=12, is_label_show=False, is_fill=True, area_opacity=0.12, line_width=2, is_smooth=True, mark_line=["average"] ,xaxis_interval=1, xaxis_rotate=45) line1 = pyecharts.Line("当日加油的隔(N-2N)天回流占比:", "%(stname)s(%(mer_id)s)-(N=%(N)s)" % re_dic, width=1500, height=600) X = data_all.query('spr_id==11')['batch_date'].tolist() N1today_mer_rate = np.array(data_mer.query('spr_id==9')['value_c']) / np.array(data_mer.query('spr_id==8')['value_c']) N1today_all_rate = np.array(data_all.query('spr_id==9')['value_c']) / np.array(data_all.query('spr_id==8')['value_c']) Y_mer = N1today_mer_rate.round(4) Y_all = N1today_all_rate.round(4) conb_ = np.append(Y_mer,Y_all) tem_dic.update({'yaxis_min':conb_.min()*0.6}) lineadd_sted(line1, dic_smarttime, X, conb_.max() * 1.2) line1.add("油站", X, Y_mer, **tem_dic) line1.add("全平台", X, Y_all, **tem_dic) page.add(line1) line2 = pyecharts.Line("当日加油的隔(2N-3N)天回流占比:", "%(stname)s(%(mer_id)s)-(N=%(N)s)" % re_dic, width=1500, height=600) X = data_all.query('spr_id==11')['batch_date'] N2today_mer_rate = np.array(data_mer.query('spr_id==10')['value_c']) / np.array(data_mer.query('spr_id==8')['value_c']) N2today_all_rate = np.array(data_all.query('spr_id==10')['value_c']) / np.array(data_all.query('spr_id==8')['value_c']) Y_mer = N2today_mer_rate.round(4) Y_all = N2today_all_rate.round(4) conb_ = np.append(Y_mer, Y_all) tem_dic.update({'yaxis_min': conb_.min()*0.6}) lineadd_sted(line2, dic_smarttime, X, conb_.max() * 1.2) line2.add("油站:", X, Y_mer, **tem_dic) line2.add("全平台", X, Y_all, **tem_dic) page.add(line2) line2 = pyecharts.Line("最近周期加油用户中睡眠回流占比:", "%(stname)s(%(mer_id)s)-(N=%(N)s)" % re_dic, width=1500, height=600) N3_mer_rate = np.array(data_mer.query('spr_id==4')['value_c']) / np.array(data_mer.query('spr_id==2')['value_c']) N3_all_rate = np.array(data_all.query('spr_id==4')['value_c']) / np.array(data_all.query('spr_id==2')['value_c']) Y_mer = N3_mer_rate.round(4) Y_all = N3_all_rate.round(4) conb_ = np.append(Y_mer, Y_all) tem_dic.update({'yaxis_min': conb_.min() * 0.6}) lineadd_sted(line2, dic_smarttime, X, conb_.max() * 1.2) tem_dic.update({'yaxis_min': conb_.min()*0.6}) line2.add("油站", X, Y_mer, **tem_dic) line2.add("全平台", X, Y_all, **tem_dic) page.add(line2) line2 = pyecharts.Line("睡眠回流占比:", "%(stname)s(%(mer_id)s)-(N=%(N)s)" % re_dic, width=1500, height=600) N3_mer_rate = np.array(data_mer.query('spr_id==4')['value_c']) / np.array(data_mer.query('spr_id==3')['value_c']) N3_all_rate = np.array(data_all.query('spr_id==4')['value_c']) / np.array(data_all.query('spr_id==3')['value_c']) Y_mer = N3_mer_rate.round(4) Y_all = N3_all_rate.round(4) conb_ = np.append(Y_mer, Y_all) tem_dic.update({'yaxis_min': conb_.min() * 0.6}) lineadd_sted(line2, dic_smarttime, X, conb_.max() * 1.2) tem_dic.update({'yaxis_min': conb_.min() - 0.04}) line2.add("油站", X, Y_mer, **tem_dic) line2.add("全平台", X, Y_all, **tem_dic) page.add(line2) line2 = pyecharts.Line("有睡眠趋势的用户占比:", "%(stname)s(%(mer_id)s)-(N=%(N)s)" % re_dic, width=1500, height=600) N3_mer_rate = np.array(data_mer.query('spr_id==5')['value_c']) / np.array(data_mer.query('spr_id==1')['value_c']) N3_all_rate = np.array(data_all.query('spr_id==5')['value_c']) / np.array(data_all.query('spr_id==1')['value_c']) Y_mer = N3_mer_rate.round(4) Y_all = N3_all_rate.round(4) conb_ = np.append(Y_mer, Y_all) tem_dic.update({'yaxis_min': conb_.min() * 0.6}) lineadd_sted(line2, dic_smarttime, X, conb_.max() * 1.2) tem_dic.update({'yaxis_min': conb_.min() - 0.04}) line2.add("油站", X, Y_mer, **tem_dic) line2.add("全平台", X, Y_all, **tem_dic) page.add(line2) page.render(to_path)
def parser_job(i): # 工作的链接 job_url = re.search('href="(.*?)"', i).group(1) name = re.search("<h3>(.*?)</h3>", i).group(1) add = re.search("<em>(.*?)</em>", i).group(1) money = re.search('"money">(.*?)</span>', i).group(1) jy, xl = re.search('-->([\s\S]*?)\n', i).group(1).split(" / ") return {"name":name,"add":add,"job_url":job_url,"money":money,"jy":jy,"xl":xl} # 指定需要查看的技术方向 jobs = ["Java","Python"] # 创建一个页面 page = pyecharts.Page() for url in urls: if url[1] not in jobs: continue # 存储解析完成的字典 datas = [] for j in range(1,6): res = requests.get(url[0] + str(j)) data = re.findall("""<a class="position_link"([\s\S]*?)<div class="company">""",res.text) for i in data: dic = parser_job(i) if "{" in dic["xl"]: continue datas.append(dic)