def province_map(cities_data, province) -> Map: if province == '香港': opt = [{ "min": 11, "color": '#731919' }, { "min": 6, "max": 10, "color": '#f08f7f' }, { "min": 1, "max": 5, "color": '#ffb86a' }, { "value": 0, "color": '#ffffff' }] else: opt = [{ "min": 100, "color": '#731919' }, { "min": 10, "max": 99, "color": '#f08f7f' }, { "min": 1, "max": 9, "color": '#ffb86a' }, { "value": 0, "color": '#ffffff' }] c = (Map().add( "確診人數", cities_data, province, is_map_symbol_show=False).set_series_opts(label_opts=opts.LabelOpts( is_show=True, font_size=9)).set_global_opts( visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True, pieces=opt), title_opts=opts.TitleOpts(title=province + "疫情情况"), legend_opts=opts.LegendOpts(is_show=False))) return c
def get_covid_oversea_country(request): file = open("country.txt", encoding='UTF-8') country_list = [] while 1: line = file.readline() if not line: break else: country_list.append(line.replace("\n", "")) file.close() all_covid = db.covid_oversea.find({}, {'text'}).limit(500) all_text = '' for item in all_covid: all_text = all_text + item['text'] jieba.load_userdict('country.txt') all_text = re.sub( "[A-Za-z0-9\!\%\[\]\,\。\<\>\#\@\&\/\-\=\"\:\?\'\;\.\➕\_\~\,\·\!\)\(\?\{\}\【\】\°\(\)]", "", all_text) words = jieba.cut(all_text) word_list = [] for word in words: if word in country_list: word_list.append(word) data = pd.DataFrame({'country': word_list}) country_serise = data['country'].value_counts() country_name_list = [] country_value_list = [] for i in country_serise.index: country_name_list.append(country_chinese_english[str(i)]) country_value_list.append(int(country_serise[i])) c = (Map(init_opts=opts.InitOpts(width="1000px", height="580px")).add( "国家", [list(z) for z in zip(country_name_list, country_value_list)], "world", is_roam=False, is_map_symbol_show=False).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title=""), visualmap_opts=opts.VisualMapOpts(item_height=150, item_width=20, pos_left=100, pos_bottom=50), legend_opts=opts.LegendOpts(is_show=False))) return HttpResponse(json.dumps({'Code': 1, 'Data': c.render_embed()}))
def timeline_map_zrs(): tl = Timeline() for i in range(2008, 2018): map0 = (Map().add( "世界抑郁症总人数", list( zip(list(df_zrs.region.unique()), list(df_zrs["{}".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)), visualmap_opts=opts.VisualMapOpts( min_=0, max_=df_zrs["2017"].max(), series_index=0), )) tl.add(map0, "{}年".format(i)) return tl
def hotmap_location(self, filename): df = pd.read_excel(filename) row_locations = df['location'] row_location_list = [] for row_t in row_locations: row_location_list.append(row_t) num_count = Counter(row_location_list) location = [] num = [] #解析字典 for key, value in num_count.items(): location.append(key) num.append(value) c = (Map().add("", [list(z) for z in zip(location, num)], "china").set_global_opts( title_opts=opts.TitleOpts(title="淘宝T恤卖家分布图"), visualmap_opts=opts.VisualMapOpts(max_=200))) c.render(path='saler_location.html')
def timeline_map() -> Timeline: tl = Timeline() df = dfdemo() for i in range(2009, 2018): map0 = (Map().add( "国际旅游收入", 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="2009-2017年世界各国国际旅游收入(占总出口的百分比)".format(i), subtitle_textstyle_opts=opts.TextStyleOpts( color="red", font_size=10, font_style="italic")), visualmap_opts=opts.VisualMapOpts(series_index=0, max_=20), )) tl.add(map0, "{}".format(i)) return tl
def map_film() -> Map: df = pd.read_csv('./data/movie2.csv', encoding='utf-8', delimiter="\t", error_bad_lines=False) df = df.drop(columns='Unnamed: 2') # 求pname的个数 counts = df['pname'].value_counts() # print(counts) province = list(counts.index) province_values = list(counts.values) province_values = [str(i) for i in province_values] c = ( Map() .add("", [list(z) for z in zip(province, province_values)], "china") .set_global_opts( title_opts=opts.TitleOpts(title="全国影院分布情况"), visualmap_opts=opts.VisualMapOpts(max_=110), ) ) return c.render()
def map_world() -> Timeline: tl = Timeline() for i in range(2006, 2018): c = ( Map().add("中小学女生与男生的入学比例(%)", list( zip(list(df3['CountryName']), list(df3["{}".format(i)]))), "world", is_map_symbol_show=False) # .add("2017", [list(z) for z in zip(df3.CountryName, 女性受教育程度)], "world") .set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="Map- 中小学女生与男生的入学比例(%)"), visualmap_opts=opts.VisualMapOpts(min_=0.9, max_=1.08), )) tl.add(c, "{}年".format(i)) return tl
def china_map_NewAddConfirm(): map_NewAddConfirm = ( Map() .add("", [list(z) for z in zip(data_pro_newly.name, data_pro_newly.confirm)], "china") .set_global_opts(title_opts=opts.TitleOpts(title="中国疫情地图(新增确诊人数)"), visualmap_opts = opts.VisualMapOpts(is_piecewise = True, pieces=[ {"min": 500, "color": "#4F070D"}, {"min": 300, "max": 499, "color": "#780707"}, # 数据范围分段,分颜色,可以根据数据大小具体分配大小 {"min": 200, "max": 299, "color": "#B40404"}, {"min": 100, "max": 199, "color": "#CD1111"}, {"min": 1, "max": 99, "color": "#F68181"}, {"max": 0, "min": 0, "label": "0", "color": "#FFFFFF"}, ])) ) page.add(map_NewAddConfirm) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国疫情地图(新增确诊人数).txt', str(map_NewAddConfirm.dump_options_with_quotes())) return map_NewAddConfirm
def map_world1() -> Timeline: tl = Timeline() for i in range(2015, 2019): c = ( Map().add("女性参会人数占比%", list( zip(list(df2['CountryName']), list(df2["{}".format(i)]))), "world", is_map_symbol_show=False) # .add("2017", [list(z) for z in zip(df2.CountryName, 女性参会人数占比)], "world") .set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="Map- 国家议会中妇女席位的比例(%)"), visualmap_opts=opts.VisualMapOpts(min_=7, max_=50), )) tl.add(c, "{}年".format(i)) return tl
def map_base(): chinaMap = ( Map() # .add("累计确诊", maptype="world") .add("累计确诊", [list(z) for z in zip(province_name, province_total_confirm)], maptype="china", is_roam=True) .set_global_opts( title_opts=opts.TitleOpts(title="中国累计确诊数据"), visualmap_opts=opts.VisualMapOpts(max_=3600, is_piecewise=True, pieces=[{"max": 0, "label": '0人'}, {"min": 1, "max": 9, "label": '1-9人'}, {"min": 10, "max": 99, "label": '10-99人'}, {"min": 100, "max": 499, "label": '100-499人'}, {"min": 500, "max": 999, "label": '500-999人'}, {"min": 1000, "max": 9999, "label": '1000-9999人'}, {"min": 10000, "label": '10000人及以上'}]), ) ) return chinaMap
def Birth_map() -> Timeline: a = Timeline() for i in range(2010, 2018): map0 = (Map().add( "世界青春期女性生育率", list(zip(list(青春生育率.CountryName), list(青春生育率["{}".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_textstyle_opts=opts.TextStyleOpts( color="red", font_size=10, font_style="italic")), visualmap_opts=opts.VisualMapOpts(series_index=0, max_=187), )) a.add(map0, "{}".format(i)) return a.render_embed()
def china_map_picture(self,seriesname:list, x_data, y_data): print(x_data) print(y_data) c = ( Map(init_opts=self.init_opts) .add(seriesname[0], [list(z) for z in zip(x_data, y_data)], "china") .set_global_opts(title_opts=opts.TitleOpts(title=self.title, subtitle=self.subtitle), # 分段类型 visualmap_opts=opts.VisualMapOpts(max_=200) # 添加logo # graphic_opts=self.logo ) ) # 返回option return c
def China(self,area,confirmed,time): pieces=[ {'max':100000,'min':10001,'label':'>50000','color':'#8A0808'}, {'max':10000,'min':5001,'label':'100000-10000','color':'#B40404'}, {'max':5000,'min':1001,'label':'5000-1001','color':'#DF0101'}, {'max':1000,'min':101,'label':'1000-101','color':'#F5A9A9'}, {'max':100,'min':1,'label':'100-1','color':'#F5A9A9'}, {'max':0,'min':0,'label':'0','color':'#FFFFFF'}, ] c=( Map(init_opts=opts.InitOpts(width='1000px',height='880px')) .add("累计确诊人数",[list(z) for z in zip(area,confirmed)],"china") .set_global_opts( title_opts=opts.TitleOpts(title="中国疫情图",subtitle='截至'+time+'中国疫情分布图'), visualmap_opts=opts.VisualMapOpts(max_=200,is_piecewise=True,pieces=pieces), ) .render("中国疫情地图.html") )
def city(self,city,confirmed,province,time): pieces = [ {'max': 50000, 'min': 1001, 'label': '>1000', 'color': '#8A0808'}, {'max': 100, 'min': 51, 'label': '100-51', 'color': '#B40404'}, {'max': 50, 'min': 11, 'label': '50-11', 'color': '#DF0101'}, {'max': 10, 'min': 2, 'label': '10-2', 'color': '#F5A9A9'}, {'max': 5, 'min': 1, 'label': '5-1', 'color': '#F5A9A9'}, {'max': 0, 'min': 0, 'label': '0', 'color': '#FFFFFF'}, ] c = ( Map(init_opts=opts.InitOpts(width='1000px', height='880px')) .add("累计确诊人数", [list(z) for z in zip(city, confirmed)], province) .set_global_opts( title_opts=opts.TitleOpts(title=province+"疫情图", subtitle='截至' + time + '疫情分布图'), visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True, pieces=pieces), ) .render(province+"疫情地图.html") )
def getMap(): # load data from redis number = r.get(provinceNumberKey) data_pair = [] for i in range(0, int(number)): key = 'province-data-' + str(i) data_pair.append([ r.hget(key, 'province_cn'), r.hget(key, 'number'), ]) # adjust the color range based on the confirmed case range_color = [] i = 0 while i <= 1000: if i == 0: range_color.append('#ffffff') if i <= 10 and i > 0: range_color.append('#f2dadb') if i > 10 and i <= 99: range_color.append('#ce8a86') if i > 99 and i <= 980: range_color.append('#bf5a53') i = i + 1 map = (Map(init_opts=opts.InitOpts( width='100%', height='600px', page_title='coronavirus-map', )).add( zoom=1.1, is_roam=False, maptype="china", data_pair=data_pair, series_name="confirmed case", ).set_global_opts(visualmap_opts=opts.VisualMapOpts( min_=0, max_=1000, is_show=True, pos_left='left', range_color=range_color), title_opts=opts.TitleOpts(title='coronavirus-map'))) return map.render()
def map_visualmap(df, up_to_date, map_name, title_suffix='') -> Map: now_num = (df['confirmed_num'] - df['cured_num'] - df['dead_num']).tolist() c = (Map(init_opts=opts.InitOpts()).add('现有确诊人数', [ list(z) for z in zip(df['area_name'].tolist(), now_num) ], map_name).add('累计确诊人数', [ list(z) for z in zip(df['area_name'].tolist(), df['confirmed_num'].tolist()) ], map_name).add('累计治愈人数', [ list(z) for z in zip(df['area_name'].tolist(), df['cured_num'].tolist()) ], map_name).add('累计死亡人数', [ list(z) for z in zip(df['area_name'].tolist(), df['dead_num'].tolist()) ], map_name).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title=f"新型冠状肺炎最新情况(中国内地){title_suffix}", subtitle=f'数据更新至{up_to_date}', subtitle_link='https://tushare.pro/', pos_left='center', title_textstyle_opts={ 'fontWeight': 'bolder', 'fontSize': 40, 'color': '#BC3B20' }, subtitle_textstyle_opts={ 'fontSize': 20, 'fontStyle': 'normal', 'color': 'lightgrey', 'fontFamily': 'SimSun' }), legend_opts=opts.LegendOpts(pos_top='middle', pos_right='10%', orient='vertical', textstyle_opts={'fontSize': 20}, selected_mode='single'), visualmap_opts=opts.VisualMapOpts( max_=sorted(now_num)[-2] if len(now_num) > 1 else sorted(now_num)[-1], pos_top='middle', pos_left='5%', textstyle_opts={'color': 'white'}, range_text=['High', 'Low']), tooltip_opts=opts.TooltipOpts(trigger='item', formatter='{b}</br>{a}:{c}'))) return c
def drawmap(maptype, map_province_list, map_province_data): # 拿到想要的数据之后,接下来我们开始画地图 title = '' if maptype == 'china': title = '全国疫情可视化数据展示' else: title = maptype ditu = ( Map( init_opts=opts.InitOpts( width='900px', height='600px', page_title=title ) ) .add( series_name='确诊人数', data_pair=[list(z) for z in zip(map_province_list, map_province_data)], maptype=maptype, is_map_symbol_show=False # 是否显示地图上的小红点 ) .set_global_opts( legend_opts=opts.LegendOpts( is_show=False ), visualmap_opts=opts.VisualMapOpts( is_piecewise=True, pieces=[ {'min': 0, 'max': 0, 'label': '0', 'color': '#ffffff'}, {'min': 1, 'max': 9, 'label': '1-9', 'color': '#FFE5DB'}, {'min': 10, 'max': 99, 'label': '10-99', 'color': '#FF9985'}, {'min': 100, 'max': 999, 'label': '100-999', 'color': '#F57567'}, {'min': 1000, 'max': 9999, 'label': '1000-9999', 'color': '#E64546'}, {'min': 10000, 'label': '>= 10000', 'color': '#B80909'} ], # pos_top='center', textstyle_opts=opts.TextStyleOpts( color='#ffffff' ) ) ) ) return ditu
def map_base() -> Map: # 数据暂时写死:后续可以结合实时数据,进行更新 # 省和直辖市 province_distribution = { '河南': 566, '北京': 212, '河北': 21, '辽宁': 12, '江西': 391, '上海': 203, '安徽': 408, '江苏': 271, '湖南': 521, '浙江': 724, '海南': 2, '广东': 725, '湖北': 11177, '黑龙江': 121, '澳门': 1, '陕西': 128, '四川': 254, '内蒙古': 3, '重庆': 312, '云南': 6, '贵州': 2, '吉林': 3, '山西': 12, '山东': 259, '福建': 179, '青海': 1, '天津': 1, '其他': 1 } provice = list(province_distribution.keys()) values = list(province_distribution.values()) c = (Map().add("确诊人数", [list(z) for z in zip(provice, values)], "china").set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="全国实时疫情分布地图"), visualmap_opts=opts.VisualMapOpts(max_=1000), )) return c
def film_map(): df = pd.read_csv('./data/movie2.csv', encoding='utf-8', delimiter="\t", error_bad_lines=False) df = df.drop(columns='Unnamed: 2') # 求pname的个数 counts = df['pname'].value_counts() # print(counts) counts = counts.astype(str) province = list(counts.index) province_values = list(counts.values) map = ( Map() .add("全国影院分布", list(zip(province, province_values)), "china", is_map_symbol_show=False) .set_global_opts( title_opts=opts.TitleOpts(title="全国影院分布情况", subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts(color="blue", font_size=18)), visualmap_opts=opts.VisualMapOpts(min_=0, max_=110, series_index=0), ) ) return map.render_embed()
def china_map_heal(): map_heal = ( Map() .add("", [list(z) for z in zip(data_pro_tota.name, data_pro_tota.heal)], "china") .set_global_opts(title_opts=opts.TitleOpts(title="中国疫情地图(累计治愈人数)"), visualmap_opts = opts.VisualMapOpts(is_piecewise = True, pieces=[ {"min": 10000, "color": "#006400"}, {"min": 1000, "max": 9999, "color": "#008B00"}, # 数据范围分段,分颜色,可以根据数据大小具体分配大小 {"min": 500, "max": 999, "color": "#00CD66"}, {"min": 100, "max": 499, "color": "#00EE76"}, {"min": 10, "max": 99, "color": "#00FF00"}, {"min": 1, "max": 9, "color": "#00FA9A"}, {"max": 0, "min": 0, "label": "0", "color": "#FFFFFF"}, ])) ) page.add(map_heal) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国疫情地图(累计治愈人数).txt', str(map_heal.dump_options_with_quotes())) return map_heal
def timeline_map() -> Timeline: tl = Timeline() for i in range(2007, 2019): map0 = ( Map() .add( "high-tech export", list(zip(list(df.Country_Name_en), 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="{}高科技出口".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts(color="red", font_size=18, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=0, max_=30), ) ) tl.add(map0, "{}".format(i)) return tl
def timeline_map_c() -> Timeline: tl = Timeline() for i in range(2009, 2020): map0 = (Map().add( "女性劳动力参与率", (list(zip(list(dfc1.country), list(dfc1["{}".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="blue", font_size=16, font_style="italic")), visualmap_opts=opts.VisualMapOpts(min_=0, max_=100, series_index=0), )) tl.add(map0, "{}".format(i)) return tl.render_embed()
def analysisProvince(): province_count = df.groupby( 'province', as_index=True)['province'].count().sort_values() data = list( map(lambda x: x if x != '' else '未知', list(province_count.index))) # 画图 page = Page() chart1 = (Map().add( "人数", [list(z) for z in zip(data, list(province_count))], "china").set_global_opts(title_opts=opts.TitleOpts(title="好友分布(中国地图)"), visualmap_opts=opts.VisualMapOpts( max_=200, is_piecewise=False))) page.add(chart1) chart2 = (Bar().add_xaxis(data).add_yaxis( '人数', list(province_count)).set_global_opts(title_opts=opts.TitleOpts( title="好友分布柱状图"))) page.add(chart2) page.render('好友分布分析.html')
def hotmap(year): timeline_1 = Timeline() for i in range(0, 4): if i == 0: a = 'confirmed' elif i == 1: a = 'suspected' elif i == 2: a = 'dead' elif i == 3: a = 'healed' list_i = listfilter2(i) map_1 = ( Map().set_global_opts( title_opts=opts.TitleOpts(title="2020年全国各省疫情"), visualmap_opts=opts.VisualMapOpts() # 最大数据范围 ).add(a, list_i, maptype="china")) timeline_1.add(map_1, "{}".format(a)) timeline_1.render("province_confirmed.html")
def make_geo_map(self): """ 生成世界地图,根据各国电影发行量 :return: """ # print(get_current_time() + '|-------> 正在生成 世界各国电影发行量 图表...') # 导入TOP500电影数据 csv_path = os.path.abspath(os.path.join(os.path.dirname("__file__"), os.path.pardir, "moviespider", "movie_info_top500.csv")) rows = pd.read_csv(csv_path, encoding='utf-8', dtype=str) # 分析并统计数据 col_country = rows['国别'].to_frame() res = col_country.groupby('国别')['国别'].count().sort_values(ascending=False) raw_data = [i for i in res.items()] # 导入映射数据,英文名 -> 中文名 country_name = pd.read_json('countries_zh_to_en.json', orient='index') stand_data = [i for i in country_name[0].items()] # 数据转换 res_code = [] for raw_country in raw_data: for stand_country in stand_data: if stand_country[1] in raw_country[0]: res_code.append(stand_country[0]) code = pd.DataFrame(res_code).groupby(0)[0].count().sort_values(ascending=False) data = [] for k, v in code.items(): data.append([k, v]) # 制作图表 c = Map() c.add("电影发行量", data, "world") c.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) c.set_global_opts(title_opts=opts.TitleOpts(title="电影TOP500榜单中 - 世界各国电影发行量"), visualmap_opts=opts.VisualMapOpts(max_=55)) htmlPath = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "analyse_data", "世界各国电影发行量.html")) pngPath = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "analyse_data", "世界各国电影发行量.png")) # 生成html c.render(htmlPath) # 生成png # make_snapshot(snapshot, c.render(), pngPath) # print(get_current_time() + '|-------> 已生成 世界各国电影发行量 图表...') return c
def sichuanmap(): c = (Map().add("橙子销量", [list(z) for z in zip(distincts, value_sichuan)], "四川").set_global_opts( title_opts=opts.TitleOpts(title="四川销售分布"), visualmap_opts=opts.VisualMapOpts(max_=maxvalue1, is_piecewise=True, pieces=[{ "min": 0, "max": 1000 }, { "min": 1000, "max": 3000 }, { "min": 300000, "max": maxvalue1 }]), ).render("map_sichuan.html"))
def get_total_confirm_map(): total_confirm_dict = get_api.get_total_confirm_dict(api_url) #分省统计确诊患者总数字典 total_confirm_list = [[x, total_confirm_dict[x]] for x in list(total_confirm_dict)] #分省统计确诊患者总数列表 data_update_time = get_api.get_data_update_time(api_url) #api数据更新时间 total_confirm_map = ( #全国确诊统计图 Map(init_opts=opts.InitOpts()).add( "确诊患者", total_confirm_list, "china").set_global_opts( title_opts=opts.TitleOpts( title="各省累计确诊患者数", subtitle="数据更新时间:{}".format(data_update_time), pos_right="center", pos_top="5%", title_link='/now_page/', title_target='self'), visualmap_opts=opts.VisualMapOpts(max_=1500), legend_opts=opts.LegendOpts(is_show=False))) total_confirm_map.chart_id = 'totalconfirmmap' return total_confirm_map
def timeline_map(): tl = Timeline() for i in range(2015, 2018): map0 = (Map().add("世界世界肺癌生存率", list(zip(list(cf.地区), list(cf["{}年".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_=5, max_=40), )) tl.add(map0, "{}年".format(i)) return tl
def timeline_map() -> Timeline: tl = Timeline() for i in range(2000, 2017): map0 = ( Map() .add( "", list(zip(list(df2.国家), list(df2["{}".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="2000年-2017年世界各国因吸烟死亡人数".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts(color="black", font_size=16, font_style="italic")), visualmap_opts=opts.VisualMapOpts(max_=266, min_=15), ) ) tl.add(map0, "{}年".format(i)) return render_template('yx.html')
def map_gd_disease_dis() -> Map: # ->常常出现在python函数定义的函数名后面,为函数添加元数据,描述函数的返回类型,从而方便开发人员使用。 ls_gd_cities = [name + '市' for name in dic_gd_cfm.keys()] # Python3使用dict.keys()返回的是迭代器(如同遍历一般) map = ( Map(init_opts=opts.InitOpts(width="900px", height="700px")).add( '广东省', [list(z) for z in zip(ls_gd_cities, dic_gd_cfm.values())], '广东', is_map_symbol_show=False) # Python3的keys(), values(), items()返回的都是迭代器,如果需要像Python2一样返回列表,只要传给list就行了 # is_map_symbol_show=False 表示不显示符号 .set_series_opts(label_opts=opts.LabelOpts( is_show=True, formatter='{b}\n{c}例')) # 设置图例 # 地图 : {a}(系列名称),{b}(区域名称),{c}(合并数值), {d}(无) .set_global_opts( title_opts=opts.TitleOpts( title='广东省新型冠状病毒疫情地图(确诊数)', subtitle='数能工作室制作\r\n最新更新时间%s\r\n数据来源腾讯' % format(timestamp)), visualmap_opts=opts.VisualMapOpts( is_show=True, split_number=6, is_piecewise=True, # 是否为分段型 pos_top='center', pieces=[{ 'min': 50 }, { 'min': 30, 'max': 49 }, { 'min': 20, 'max': 29 }, { 'min': 10, 'max': 19 }, { 'min': 1, 'max': 9 }, { 'value': 0, "label": '无确诊病例', "color": 'green' }]))) return map