def index_bar_every_4(): prevention = request.args.get("city") df5 = pd.read_csv(r'./static/data/lvyou.csv') tl = Timeline() for i in range(2013, 2018): map0 = ( Map() .add( "", list(zip(list(df5.地区.unique()), list(df5["{}".format(i)]))), "world", is_map_symbol_show=False ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="{}年世界各地区旅游总收入".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts(color="black", font_size=16, font_style="italic")), visualmap_opts=opts.VisualMapOpts(max_=70000000000), ) ) tl.add(map0, "{}年".format(i)) return render_template('index.html', myechart=tl.render_embed(), text=''' 从上面图的走势,我们可以看出,世界各地区旅游总收入较多的国家分别是United States、France、Germany、China等国家。 ''')
def dong_scatter(data, info='', path0=''): from pyecharts import options as opts from pyecharts.commons.utils import JsCode from pyecharts.charts import Scatter, Timeline # endlist = ['canshu', 'celue_name', '预测_s_Time', '未来end_3', '最终预测值1', 'hg最终预测值1'] data['aim'] = data['canshu'] + data['celue_name'] data.rename(columns={ 'hg最终预测值1': '预测值', '未来end_3': '未来=月终收益', '预测_s_Time': 's_Time' }, inplace=True) print(data.columns) print(data.tail()) title = '动态图' df = data # data['预测值'] = data['预测值'].apply(lambda x: int(x)) min_pre = min(data['预测值'].values.tolist()) max_pre = max(data['预测值'].values.tolist()) # df['未来=月终收益']=df['未来=月终收益'].apply(lambda x: int(x)) # df['预测值']=df['预测值'].apply(lambda x: int(x)) df['s_Time'] = pd.to_datetime( df['s_Time']) #.apply(lambda x:x.strftime(format="%Y-%m-%d")) df.sort_values(by=['s_Time'], ascending=True, inplace=True) tl = Timeline() timelist = list(set(df['s_Time'].tolist())) print(list(set(df['s_Time'].tolist()))) sorted(timelist) # df_date = [time.strftime('%Y-%m-%d',time.localtime(i/1000000000) ) for i in timelist] # print(df_date) for k, i in enumerate(sorted(timelist)): # print(k,i) xdata = df.loc[df['s_Time'] == i, '预测值'].values.tolist() ydata = df.loc[df['s_Time'] == i, ['未来=月终收益', '预测值']].values.tolist() # print(ydata) Scatter0 = (Scatter().add_xaxis(xdata).add_yaxis( '未来=月终收益', ydata, label_opts=opts.LabelOpts(is_show=False) ).set_series_opts().set_global_opts( xaxis_opts=opts.AxisOpts( name='预测值:', type_="value", axistick_opts=opts.AxisTickOpts(is_show=True)), yaxis_opts=opts.AxisOpts( name='真实值:', type_="value", axistick_opts=opts.AxisTickOpts(is_show=True)), title_opts=opts.TitleOpts(title=f"{title}==:{i}月份的数据"), tooltip_opts=opts.TooltipOpts(formatter=JsCode( "function (params) { return '真实:'+params.value[1] +' == 预测:'+ params.value[2];}" )), visualmap_opts=opts.VisualMapOpts(min_=min_pre, max_=max_pre), )) tl.add(Scatter0, "{}月".format(i)) tl.render(path0 + f"{info}.html") print(path0 + f"{info}.html")
def temp_show(field, name, path): # 定义时间滚动栏标题 title = TQHBTrans().get_date() print(title) # 创建时间线对象 tl = Timeline() for i in range(len(title)): print(i) data = TQHBTrans().get_temp(title[i], field) # 定义地图标题 map_title = str(title[i])[0:4] + "年" + str(title[i])[4:6] + "月" + str( title[i])[6:8] + "日全国各省会" + name + "分布图" # 创建地图对象 map0 = Map() # 向地图中添加数据 map0.add("", data, "china") # 创建地图显示方式 map0.set_global_opts(title_opts=opts.TitleOpts(title=map_title, ), visualmap_opts=opts.VisualMapOpts( is_piecewise=True, pieces=[{ "max": 40, "min": 31, "label": "31-40℃", "color": "#FF8000" }, { "max": 30, "min": 21, "label": "21-30℃", "color": "#FFBB77" }, { "max": 20, "min": 11, "label": "11-20℃", "color": "#FFDCB9" }, { "max": 10, "min": 1, "label": "1-10℃", "color": "#FFEEDD" }, { "max": 0, "min": -10, "label": "-10-0℃", "color": "#C4E1FF" }, { "max": -11, "min": -20, "label": "-20--11℃", "color": "#66B3FF" }, { "max": -21, "min": -30, "label": "-30--21℃", "color": "#2894FF" }])) # 将地图添加到时间线中 tl.add(map0, title[i]) # 生成html文件 tl.render(path)
def finacial_education_map() -> Timeline: kd = Timeline() #添加时间轴 for i in range( 2009, 2019 ): #选取时间段为2009-2018年,由于range(start, stop[, step]),所以是(2009,2019) map1 = ( Map().add( "地方财政教育支出(亿元)", list(zip(list(df1.provinces), list(df1["{}".format(i)]))), "china", #选取中国地图 is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title='图1', subtitle="{}各省财政教育支出".format(i), subtitle_textstyle_opts=opts.TextStyleOpts( color="black", font_size=18, )), # 设置标题与副标题样式,进行图例说明 visualmap_opts=opts.VisualMapOpts(min_=df1["2009"].min(), max_=df1["2018"].max(), series_index=0), #设置最大最小值 )) kd.add(map1, "{}".format(i)) return kd #返回数据
def index_bar(): df = pd.read_csv("./static/data/country_females.csv") tl = Timeline() for i in range(2014, 2018): map0 = (Map().add("女性患病率", list(zip(list(df.Country), list(df["{}".format(i)]))), "world", is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title="{}年女性患病率".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=10, max_=20))) tl.add(map0, "{}年".format(i)) return render_template('index.html', myechart=tl.render_embed(), text=''' 女性心理健康患病率在国家和地区间的分布大致同男性的差不多。 经济较发达的欧洲、美洲及大洋洲的心理健康患病率的比例较高 且四年间的变化趋势也趋于稳定,这与经济和社会发展水平有着密切联系, 随着社会医疗保障体系的完善,心理健康患病率正趋于稳定和下降趋势。''')
def index_bar_every_1(): df = pd.read_csv('./static/data/renjunGDP.csv', index_col=0) df1 = pd.read_csv('./static/data/pinkunlv.csv', index_col=0) df2 = pd.read_csv('./static/data/pinkunrenkou.csv', index_col=0) tl = Timeline() for i in range(2010, 2018): map0 = (Map().add( "各国贫困率跟贫困人口的关系", [(city[i], j) for i, j in zip(list(df2.index), list(df1['{}年'.format(i)])) if city.get(i, None)], "world", is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title="{}各国贫困率跟贫困人口的关系".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=-1, max_=11.5), )) tl.add(map0, "{}年".format(i)) return render_template( 'index.html', myechart=tl.render_embed(), result=df.values.tolist(), a=1, data_x=df.columns.values.tolist()[1:], text1='''通过贫困率和贫困人口的两张地图对比可得,地图都有类似的点 两张地图颜色分布和变化趋势大致相同, 可以得出贫困率跟贫困人口相关。 两份数据图的中东地区数据是都偏大的随着年份的增加,变化都不是很大 我们还可以看出随着年份的增加,尽管全球总体贫困率有所下降,尤其是在中国和拉丁美洲的多数地区, 但非洲和部分亚洲地区的贫困率仍居高不下。 通过各国人均GDP和贫困率的两张地图对比可得到: 人均GDP和贫困率有一定的关系,欧洲有些高收入国家贫困率的数据也不低,说明人均GDP与贫困率的关系不大,但是也有一定的关系。看人均GDP和贫困人口,不能全面衡量和比较国与国之间贫困率的差异贫富差距和社会保障 ,是决定国家贫困率的另外两个重要因素。''')
def render_map(date_list, cy_name_list, ncov_data) -> Map: tl = Timeline() tl.add_schema(is_auto_play=True, play_interval=60, is_loop_play=False, width=700) for date_str in date_list: map_ = (Map(init_opts=opts.InitOpts( bg_color='rgba(255,250,205,0.2)', width='1000px', height='600px', page_title='page', theme=ThemeType.MACARONS)).add( "全球疫情变化", [list(z) for z in zip(cy_name_list, ncov_data[date_str])], "world", is_map_symbol_show=False, name_map=countries_dict).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="19-nCoV\n%s" % date_str), legend_opts=opts.LegendOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(max_=3000))) tl.add(map_, "%s" % date_str) tl.render("nCoV全球疫情地图({}).html".format(datetime.date.today()))
def index_bar(): df = pd.read_csv('./static/data/average_salary.csv', index_col=0, error_bad_lines=False) tl = Timeline() for i in range(2013, 2019): map0 = (Map().add( "average_salary", list(zip(list(df.index), list(df["{}".format(i)]))), "china", is_map_symbol_show=False).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts( title="{}年平均工资".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=20000, max_=100000), )) tl.add(map0, "{}".format(i)) return render_template( 'index.html', myechart=tl.render_embed(), text=''' 分析2013年到2018年人们生活水平的变化''', text1='''首先从地图轮播的图表来看,北京和上海始终处于高收入的地区,而西藏从2015年开始有非常明显的提升。 到了2017年,我国各地的平均年收入基本达到了六万左右,并且逐年递增。''')
def draw_account(trader_name): df_account = get_account(trader_name=trader_name) df_position = get_position(trader_name=trader_name) xdata = [to_time_str(timestamp) for timestamp in df_account.index] ydata = df_account.loc[:, 'all_value'].values.tolist() line = (Line().add_xaxis(xdata).add_yaxis("市值曲线", ydata).set_global_opts( title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"), legend_opts=opts.LegendOpts(pos_top="48%"), )) time_line = Timeline() for timestamp in df_position.index: positions = zip( df_position.loc[timestamp, ['security_id']].values.tolist(), df_position.loc[timestamp, ['value']].values.tolist()) security_positions = [(x[0], y[0]) for x, y in positions] print(security_positions) pie = Pie().add("持仓", security_positions) time_line.add(pie, to_time_str(timestamp)) page = Page() page.add(line, time_line) return page
def print_bar(): x = ["no PV", "PV"] timeline1 = Timeline(init_opts=opts.InitOpts(bg_color="black")) for i in range(len(Grid)): price_noPV[i] = ('%.2f' % price_noPV[i]) price_opti[i] = ('%.2f' % price_opti[i]) bar = (Bar(init_opts=opts.InitOpts( bg_color="black")).add_xaxis(x).add_yaxis( "overall income", [price_noPV[i], price_opti[i]], color="rgb(30,144,255)", label_opts=opts.LabelOpts()).reversal_axis().set_series_opts( label_opts=opts.LabelOpts(position="right")). set_global_opts( title_opts=opts.TitleOpts( title="The overall income(USD) till time {}".format( time[i]), title_textstyle_opts=opts.TextStyleOpts(color="white")), yaxis_opts=opts.AxisOpts(axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(color="white"), ), axislabel_opts=opts.LabelOpts()), xaxis_opts=opts.AxisOpts(axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(color="white")), axislabel_opts=opts.LabelOpts()), legend_opts=opts.LegendOpts( textstyle_opts=opts.TextStyleOpts(color="white"), pos_left="right", pos_top="0%"), )) timeline1.add(bar, "{}年".format(i)).add_schema(play_interval=2000, is_auto_play=True, is_timeline_show=False) timeline1.render("C:/Users/suqi/Desktop/allcode/barnew.html")
def gauge1() -> Timeline: timeline3 = Timeline(init_opts=opts.InitOpts( width="270px", height="180px", bg_color="black")) for i in range(len(Grid)): b = batteryenergy[i] / 900 * 100 gauge0 = (Gauge(init_opts=opts.InitOpts( width="270px", height="180px", bg_color="black")).add( series_name="grid", data_pair=[["", round(b, 1)]], max_=100, min_=0, start_angle=210, split_number=5, end_angle=-30, axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(color=[( 0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=20)), detail_label_opts=opts.LabelOpts(formatter="{value}%", font_size=12), radius="80%").set_global_opts( legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts( is_show=True, formatter="{a} <br/>{b} : {c}%"), title_opts=opts.TitleOpts( "Percentage of battery energy at time {}".format( time[i]), title_textstyle_opts=opts.TextStyleOpts( color="white", font_size=10.5)))) timeline3.add(gauge0, "{}年".format(i)).add_schema( is_timeline_show=True).add_schema(play_interval=2000, is_auto_play=True, is_timeline_show=False) return timeline3
def weather_show(path): # 定义时间线标题 title = ["最高气温", "昼夜温差", "降水量"] # 定义查询字段 field = ["high_temp", "differ_temp", "precipitation"] # 定义标记单位 remarks = ["温度(℃)", "温度(℃)", "降水量(mm)"] # 定义时间线对象 tl = Timeline() for i in range(3): # 查询数据 name, value = WeatherTrans().get_data(field[i], field[i]) # 统计表标题 bar_title = "2020年3月15日全国" + title[i] + "Top 10 城市" # 定义柱状图对象 bar = Bar() # 添加横坐标 bar.add_xaxis(name) # 添加纵坐标 bar.add_yaxis(remarks[i], value, label_opts=opts.LabelOpts(position="right")) # 绘制横向统计图 bar.reversal_axis() # 添加标题 bar.set_global_opts(title_opts=opts.TitleOpts(bar_title)) # 将统计图添加到时间线中 tl.add(bar, title[i]) # 生成html文件 tl.render(path)
def theme_macarons(make_new, tag): tl = Timeline(init_opts=opts.InitOpts( theme=ThemeType.MACARONS)) # theme=ThemeType.PURPLE_PASSION tl.add_schema( pos_bottom='-7px', is_auto_play=True, symbol_size=[20, 20], play_interval=2000, ) for i in range(2015, 2020): bar = Bar() bar.add_xaxis(list(make_new.columns)) bar.add_yaxis("", list(make_new.loc[i, :].values), label_opts=opts.LabelOpts(is_show=False)) bar.set_colors([ random.choice([ 'blue', 'rgba(100,255,0,0.8)', '#5793f3', '#007A99', 'yellow' ]) ]) bar.set_global_opts( xaxis_opts=opts.AxisOpts(name="", axislabel_opts={"rotate": 40}), title_opts=opts.TitleOpts("{}-{}指数".format(i, tag))) tl.add(bar, "{}年".format(str(i))) return tl
def index_bar_every_1_tp(): df = pd.read_csv("./static/data/lvyou.csv") df2 = pd.read_csv("./static/data/gdp.csv") x = list(df.地区) tl = Timeline() for i in range(2013, 2018): bar = ( Bar() .add_xaxis(x) .add_yaxis("世界各地区旅游总收入", list(df["{}".format(i)])) .add_yaxis("世界各地区GDP总量", list(df2["{}".format(i)])) .reversal_axis() .set_global_opts(title_opts=opts.TitleOpts("{}年世界各地区旅游总收入与GDP总量对比".format(i)), datazoom_opts=opts.DataZoomOpts(orient="vertical")) .set_series_opts( label_opts=opts.LabelOpts(is_show=False), ) ) tl.add(bar, "{}年".format(i)) return render_template('index.html', myechart=tl.render_embed(), text=''' 总体上看世界各地区旅游总收入是和与GDP总量成正比的,从图表数据看两者都有些增长,但增长有些波动总体上还是趋向平稳的 ''')
def Create_Combine(my_data, ave_data, exam_name, class_data, grade_data, Exam_Number): #历次排名对比 tab = Tab() The_Line = Create_Line(class_data, grade_data) tab.add(The_Line, "历次排名") tab.add(table_base(), "参考上线排名") #不同考试成绩概况 t1 = Timeline() for i in range(len(ave_data)): Now_Bar = Create_Bar(my_data[i], ave_data[i], exam_name[i], "你的成绩", "平均分", False) t1.add(Now_Bar, exam_name[i]) tab.add(t1, "近段考试概况") #历次单科成绩对比 for i in range(0, 6): clone_score = [] for j in range(len(exam_name)): clone_score.append(my_data[j][i]) clone_rank = [] for j in range(len(exam_name)): clone_rank.append(All_Exam_RANK[j][i]) tab.add(Create_Line_RANK(clone_score, clone_rank), Subject[i]+"走势") tab.render(str(Exam_Number)+"的综合分析.html")
def timeline_sankey() -> Timeline: tl = Timeline() names = ("商家A", "商家B", "商家C") nodes = [{"name": name} for name in names] for i in range(2015, 2020): links = [ {"source": names[0], "target": names[1], "value": Faker.values()[0]}, {"source": names[1], "target": names[2], "value": Faker.values()[0]}, ] sankey = ( Sankey() .add( "sankey", nodes, links, linestyle_opt=opts.LineStyleOpts( opacity=0.2, curve=0.5, color="source" ), label_opts=opts.LabelOpts(position="right"), ) .set_global_opts( title_opts=opts.TitleOpts(title="{}年商店(A, B, C)营业额差".format(i)) ) ) tl.add(sankey, "{}年".format(i)) return tl
def score_map() -> Timeline: conn = mysql.connector.connect(**happiness) cursor = conn.cursor() SQL = "SELECT * FROM score" cursor.execute(SQL) u = cursor.fetchall() cols = cursor.description conn.commit() conn.close() col = [] for i in cols: col.append(i[0]) data = list(map(list, u)) data = pd.DataFrame(data, columns=col) print(data) tl = Timeline() for i in range(2015, 2018): map0 = ( Map() .add( "世界幸福分数", list(zip(list(data.country), list(data["score_{}".format(i)]))), "world", is_map_symbol_show=False ) .set_global_opts( title_opts=opts.TitleOpts(title="{}年世界幸福分数".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts(color="red", font_size=18, font_style="italic")), # 设置副标题样式,进行图例说明 visualmap_opts=opts.VisualMapOpts(min_=data['score_2016'].min(), max_=data['score_2016'].max(), series_index=0), ) ) tl.add(map0, "{}".format(i)) return tl
def gcv_main(): """ TODO """ # 生成时间轴的图 timeline = Timeline( init_opts=opts.InitOpts(width="1600px", height="800px")) commit_log = repo_analyze() contribute = {} for item in commit_log.itertuples(): top_commiter = get_topX(contribute, item, 5) timeline.add(get_commits_chart(time=item[1], \ names=top_commiter['author'].tolist(), \ c_insert=top_commiter['v1'].tolist(), \ c_delete=top_commiter['v2'].tolist(), \ c_add=top_commiter['v0'].tolist()), \ time_point=item[1]) # 1.0.0 版本的 add_schema 暂时没有补上 return self 所以只能这么写着 timeline.add_schema(is_auto_play=True, play_interval=100) timeline.render("git.html")
def index_bar_every(): df = pd.read_csv('./static/data/renjunGDP.csv') tl = Timeline() for i in range(2010, 2018): c = (Map().add( "世界地图", [(city[i], j) for i, j in zip(list(df['Country Name']), list(df['{}年'.format( i)])) if city.get(i, None)], "world").set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="{}各国人均GDP".format(i)), visualmap_opts=opts.VisualMapOpts(max_=80), )) tl.add(c, "{}年".format(i)) return render_template( 'index.html', myechart=tl.render_embed(), result=df.values.tolist(), a=1, data_x=df.columns.values.tolist()[1:], text1='''通过贫困率和贫困人口的两张地图对比可得,地图都有类似的点 两张地图颜色分布和变化趋势大致相同, 可以得出贫困率跟贫困人口相关。 两份数据图的中东地区数据是都偏大的随着年份的增加,变化都不是很大 我们还可以看出随着年份的增加,尽管全球总体贫困率有所下降,尤其是在中国和拉丁美洲的多数地区, 但非洲和部分亚洲地区的贫困率仍居高不下。 通过各国人均GDP和贫困率的两张地图对比可得到: 人均GDP和贫困率有一定的关系,欧洲有些高收入国家贫困率的数据也不低, 说明人均GDP与贫困率的关系不大,但是也有一定的关系。看人均GDP和贫困人口,不能全面衡量和比较国与国之间贫困率的差异贫富差距和社会保障,是决定国家贫困率的另外两个重要因素。''' )
def timeline_bar() -> Timeline: x = Reason tl = Timeline() for i in time: df2 = df[df.Year == int(i)] n1 = [] n2 = [] n3 = [] n4 = [] n5 = [] for a in Reason: df3 = df2[df2['Cause of Death'] == a] n1.append(sum(df2['Potentially Excess Deaths'][(df['State'] == 'United States')][(df['Cause of Death'] == 'Heart Disease')])) n2.append(sum(df2['Potentially Excess Deaths'][(df['State'] == 'United States')][(df['Cause of Death'] == 'Cancer')])) n3.append(sum(df2['Potentially Excess Deaths'][(df['State'] == 'United States')][(df['Cause of Death'] == 'Chronic Lower Respiratory Disease')])) n4.append(sum(df2['Potentially Excess Deaths'][(df['State'] == 'United States')][(df['Cause of Death'] == 'Stroke')])) n5.append(sum(df2['Potentially Excess Deaths'][(df['State'] == 'United States')][(df['Cause of Death'] == 'Unintentional Injury')])) bar = ( Bar() .add_xaxis(x) .add_yaxis("Heart Disease", n1) .add_yaxis("Cancer", n2) .add_yaxis("Chronic Lower Respiratory Disease", n3) .add_yaxis("Stroke", n4) .add_yaxis("Unintentional Injury", n5) .set_global_opts(title_opts=opts.TitleOpts("美国{}年药物中毒死亡人数".format(i))) ) tl.add(bar, "{}年".format(i)) return tl
def timeline_map() -> Timeline: df = pd.read_csv("API_worldap2shijianzhou.csv") tl = Timeline() for i in range(2010, 2018): map0 = ( Map() .add( "pm2.5浓度", list(zip(list(df.CountryName), list(df["{}".format(i)]))), "world", is_map_symbol_show=False ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="2010-2017年世界空气污染程度".format(i), subtitle_textstyle_opts=opts.TextStyleOpts(color="red", font_size=10, font_style="italic")), visualmap_opts=opts.VisualMapOpts(series_index=0, max_=99.73437372), ) ) tl.add(map0, "{}".format(i)) map0.render("./templates/world_airp.html") with open("./templates/world_airp.html", encoding="utf8", mode="r") as f: sym = "".join(f.readlines()) return render_template('result.html', the_sym=sym, )
def bar_datazoom_inside() -> Timeline: tl = Timeline() for i in range(2014, 2020): c = ( Bar( init_opts=opts.InitOpts( animation_opts=opts.AnimationOpts( animation_delay=1000, animation_easing="elasticOut" ) ) ) .add_xaxis(list(zip(list(data总.set_index('类别').index)))) .add_yaxis("显示",list(data总["{}".format(i)])) .set_global_opts( title_opts=opts.TitleOpts(title="纵横小说月票榜"), datazoom_opts=opts.DataZoomOpts(type_="inside"), visualmap_opts=opts.VisualMapOpts(type_="color", max_=250000, min_=200,pos_right='20',pos_top='middle'), toolbox_opts=opts.ToolboxOpts(), ) .set_series_opts( label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts( data=[ opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="min", name="最小值"), ] ), ) ) tl.add(c, "{}年".format(i)) return tl
def get_grid_timeline(column, label, df_city, df_province, df_cn, min_num, max_num, range_color): pass timeline = Timeline(init_opts=opts.InitOpts( width="1500px", height="850px", theme=ThemeType.DARK)) time_list = df_city['date'].unique().tolist() for y in time_list: g = gird_chart(column=column, label=label, target_date=y, df_city=df_city, df_province=df_province, df_cn=df_cn, min_num=min_num, max_num=max_num, range_color=range_color) timeline.add(g, time_point=str(y)) timeline.add_schema( orient="vertical", # is_auto_play=True, is_inverse=True, play_interval=5000, pos_left="null", pos_right="5", pos_top="20", pos_bottom="20", width="60", label_opts=opts.LabelOpts(is_show=False, color="#fff"), ) return timeline
def radar_product_rating_base(): """ 此函数用于获取产品多维评价的雷达图的参数。 Returns ------- tl : TYPE-echarts parameters return echarts parameters. """ # data query dataX, products, list_dataY = product_rating_query() c_schema = [] for i in range(len(dataX)): c_schema.append({"name":dataX[i],"max":5,"min":0}) # Declare objects, render pictures tl = Timeline() for i in range(len(products)): c = ( Radar(init_opts=opts.InitOpts(width="1280px", height="720px")) .add_schema(schema=c_schema, splitarea_opt=opts.SplitAreaOpts(is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), textstyle_opts=opts.TextStyleOpts(color="#fff"), ) .add(series_name=products[i], data=[list(list_dataY[i])], linestyle_opts=opts.LineStyleOpts(color="#CD0000"), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=True)) .set_global_opts(title_opts=opts.TitleOpts(title="Multi-dimensional analysis of product performance"), legend_opts=opts.LegendOpts(pos_left="80%", pos_top="50%")) ) tl.add(c, "{}".format(products[i])) return tl
def index_word(): df = pd.read_csv("./static/data/country_males.csv") tl = Timeline() for i in range(2014, 2018): map0 = (Map().add("男性患病率", list(zip(list(df.Country), list(df["{}".format(i)]))), "world", is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title="{}年女性患病率".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=10, max_=20))) tl.add(map0, "{}年".format(i)) return render_template('index.html', myechart=tl.render_embed(), text=''' 由地图可知2014年-2017年亚洲、俄罗斯及部门南美洲地区的男性心理健康患病率 比欧洲、美国、澳洲要低,由此可见发达国家和地区患心理健康疾病的比例也比欠 发达的国家和地区高。且四年间的变化率不大,相对于较稳定趋势。''')
def get_index(): timeline = Timeline( # init_opts=opts.InitOpts(width="1600px", height="900px", theme=ThemeType.DARK) init_opts=opts.InitOpts( width="100vw", height="100vh", theme=ThemeType.DARK)) for day in date_list: g = get_week_chart(date=day) timeline.add(g, time_point=day) timeline.add_schema( orient="vertical", is_auto_play=True, is_inverse=True, play_interval=2000, pos_left="null", pos_right="20", pos_top="10", pos_bottom="10", width="60", label_opts=opts.LabelOpts(is_show=False, color="#fff"), ) # timeline.render("china_gdp_from_1993_to_2018.html") return render_template( "demo.html", # passed_data=msg_data, myechart=timeline.render_embed(), )
def charts(): fp = open('./oldData.txt', 'r') # Timeline timeline = Timeline(init_opts=opts.InitOpts( width="1660px", height="708px", )) # 48 bar charts for i in range(48): X, Y, Color = getSta(fp) # y-axle with color y = [] for j in range(22): y.append( opts.BarItem( name=X[j], value=Y[j], itemstyle_opts=opts.ItemStyleOpts(color=Color[j]))) # single bar chart bar = ( Bar().add_xaxis(X).add_yaxis( "Youbike 使用率", y).reversal_axis().set_global_opts( title_opts=opts.TitleOpts( title="南港區Youbike的一天", pos_left="center", ), legend_opts=opts.LegendOpts(pos_left="left"), graphic_opts=[ opts.GraphicGroup( # add a block graphic_item=opts.GraphicItem(left="80%", top="80%"), children=[ opts.GraphicText( # add text into the block graphic_item=opts.GraphicItem( left="center", top="center", # z=100 ), graphic_textstyle_opts=opts. GraphicTextStyleOpts( text="{}".format(invTime[i]), font="48px Verdana", ), ) ]) ]).set_series_opts( # number showed at right of the bar label_opts=opts.LabelOpts(position="right", color="#333"))) timeline.add(bar, "") # add single bar chart into timeline timeline.add_schema(play_interval=1000, is_loop_play=True) # play settings # export into HTML timeline.render("YoubikeUsingRate.html") fp.close()
def index_bar_every(): df1 = pd.read_csv("./static/data/dependency_ratio.csv", index_col="地区") tl = Timeline() for i in range(2014, 2019): map0 = (Map().add("抚养比", list(zip(list(df1.index), list(df1["{}年".format(i)]))), "china", is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title="{}抚养比".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=23, max_=51), )) tl.add(map0, "{}年".format(i)) return render_template('index.html', myechart=tl.render_embed(), text1=''' 其实,从中国整体来看,抚养比基本都是在逐年上升的; 根据最新一年(2018年)的分省抚养比数据来看: 贵州、山东、及其附近的省份【集中在地图中心区域的省份】的抚养比也是相对较高的; 结合上一个图表,我们可以得出结论:中国分省离婚率的上涨和抚养比是有一定关系的【抚养比:劳动力的抚养负担】 ''')
def wordY(): df = pd.read_csv("./static/data/greens.csv") prevention = request.args.get("city1", "emissions") tl = Timeline() for i in range(2014, 2018): map0 = (Map().add("城市绿化覆盖率", list( zip(list(df.province), list(df["{}年".format(i)]))), "china", is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title="{}年城市绿化覆盖率".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=30, max_=50))) tl.add(map0, "{}年".format(i)) return render_template( 'index.html', myechart=tl.render_embed(), text=''' 总体上2014年到2017年各省份的城市绿化覆盖率在增加极少的经济欠发达省份如西藏的城市绿化覆盖率在这近四年减少''', text1= '''由各年份城市绿化覆盖率图可以知道,经济越发达的省份城市绿化程度更好,如青海、西藏、新疆等省份经济欠发达的省份城市绿化程度相对比较差 东部沿海省份城市的城市绿化覆盖率最高,例如山东、江苏、浙江、福建、广东等省份''')
def index_bar_every_4(): df = pd.read_csv("./static/data/wuhai.csv") tl = Timeline() for i in range(2009, 2018): map0 = (Map().add("垃圾无害化清理率(单位:百分比)", list(zip(list(df.地区), list(df["{}".format(i)]))), "china", is_map_symbol_show=False).set_global_opts( title_opts=opts.TitleOpts( title="{}各省垃圾无害化清理率".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts( min_=min(list(df["{}".format(i)])), max_=max(list(df["{}".format(i)]))), )) tl.add(map0, "{}".format(i)) return render_template('index.html', myechart=tl.render_embed(), text=''' 垃圾无害化处理的工艺主要有:卫生填埋、堆肥和焚烧三种。 由垃圾无害化处理率地图可见,一开始,各省的处理率都十分不平均,高的高达97,低的低达29,西藏在2016年之前甚至没有数据。直到2016年后,全国的垃圾无害化处理都基本达到了90%。 ''', text1='''我对影响垃圾无害化处理的因素的猜测如下: 1.高纬度的地方天气寒冷,卫生填埋在地下分解的时间很长,因此导致无害化处理的进度缓慢。 2.西藏等地区,并不进行农业,堆肥的无害化处理方式并不适合此些地区,也将导致其无法无害化处理垃圾 3.人口密度高的地区无法进行焚烧、填埋,因为人类生活用地面积就极大''')