def ChinanowdayMap(): # 中国今日地理图 data = pd.read_excel(readPath + '中国各省市总体疫情信息/中国各省市(区)今日新增疫情信息.xlsx', index_col=False) data_name = data['name'] data_confirm = data['confirm'] chinaMap = ( Map() .add('', [list(z) for z in zip(data_name, data_confirm)], maptype='china') .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_series_opts() .set_global_opts( title_opts=opts.TitleOpts(title="中国各省市(区)今日新增疫情信息"), visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=[{"max": 0, "label": '0人', "color": "#FFFAFA"}, {"min": 1, "max": 9, "label": '1-9人', "color": "#F08080"}, {"min": 10, "max": 99, "label": '10-99人', "color": "#BC8F8F"}, {"min": 100, "max": 499, "label": '100-499人', "color": "#A52A2A"}, {"min": 500, "max": 999, "label": '500-999人', "color": "#B22222"}, {"min": 1000, "max": 9999, "label": '1000-9999人', "color": "#8B0000"}, {"min": 10000, "label": '10000人及以上', "color": "#800000"}]), ) ) path = savePath + '中国各省市总体疫情信息/' isExists = os.path.exists(path) # 判断当前目录是否有中国各省市(区)总体疫情信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市总体疫情信息/中国各省市(区)今日新增疫情信息.html') if flag: dwf.write_to_file(path + '中国各省市(区)今日新增疫情信息.txt', str(chinaMap.dump_options_with_quotes()))
def analyse_Chinahistory(): China_history = pd.DataFrame( pd.read_excel(readPath + '/中国总体历史疫情信息/历史总体信息.xlsx')) CNhis_date = list(China_history['date']) CNhis_confirm = list(China_history['confirm']) CNhis_suspect = list(China_history['suspect']) CNhis_dead = list(China_history['dead']) CNhis_heal = list(China_history['heal']) CNhis_nowConfirm = list(China_history['nowConfirm']) CNhis_nowSevere = list(China_history['nowSevere']) CNhis_importedCase = list(China_history['importedCase']) CNhis_deadRate = list(China_history['deadRate']) CNhis_healRate = list(China_history['healRate']) CNhis_noInfect = list(China_history['noInfect']) line_CNhis=\ ( Line() .add_xaxis(xaxis_data=CNhis_date)#xaxis_data为x轴,y_axis为y轴 .add_yaxis(series_name='累计确诊',y_axis=CNhis_confirm,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='疑似病例',y_axis=CNhis_suspect,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡病例',y_axis=CNhis_dead,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈病例',y_axis=CNhis_heal,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='现有确诊',y_axis=CNhis_nowConfirm,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='现有重症',y_axis=CNhis_nowSevere,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='境外输入病例',y_axis=CNhis_importedCase,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='无诊感染者人数',y_axis=CNhis_noInfect,label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国疫情走势',pos_left='37%',pos_top='5%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='人数')) )#创建折线图 line_CNhis_rate=\ ( Line() .add_xaxis(xaxis_data=CNhis_date)#xaxis_data为x轴,y_axis为y轴 .add_yaxis(series_name='治愈率',y_axis=CNhis_healRate,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡率',y_axis=CNhis_deadRate,label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国累计治疗率、死亡率',pos_left='37%',pos_top='5%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='百分比')) )#创建折线图 # line_CNhis.render(savaPath+'\\Chinahistory.html')#将生成的图像保存为html文件并存放在analisis文件夹 # line_CNhis_rate.render(savaPath+'\\Chinahistoryrate.html')#将生成的图像保存为html文件并存放在analisis文件夹 page.add(line_CNhis) #将图像加入同一页 page.add(line_CNhis_rate) #将图像加入同一页 """ 很明显,湖北地区的死亡人数,确诊人数相比其他地区要高的多。湖北地区最早爆发疫情,因此很多人也相信新冠肺炎的发源地是来自于武汉的华南海鲜市场, 而这些病毒是从野生动物身上传到人体身上的。随着事态发展,一些关键的研究出来了,权威的科学杂志Science上发表了一篇文章, 最早的一批患者有一部分人没有华南海鲜市场接触史。因此他们推断华南海鲜市场可能并不是新冠肺炎的起源地。故疫情当前,我们应该做的不是互相推卸责任, 而是共同抵抗病毒的入侵,对于了解病毒的真实来源,更应该看数据说话,不应该听信谣言,更不应该散播谣言。 """ if flag: dwf.write_to_file(savaPath + '/中国疫情走势.txt', str(line_CNhis.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/中国累计治疗率、死亡率.txt', str(line_CNhis_rate.dump_options_with_quotes())) return line_CNhis, line_CNhis_rate
def analyse_province(): Province = pd.DataFrame( pd.read_excel(readPath + '/中国各省市总体疫情信息/中国各省市总体疫情信息.xlsx')) prov_nowConfirm = list(Province['nowConfirm']) prov_confirm = list(Province['confirm']) prov_suspect = list(Province['suspect']) prov_dead = list(Province['dead']) prov_deadRate = list(Province['deadRate']) prov_showRate = list(Province['showRate']) prov_heal = list(Province['heal']) prov_healRate = list(Province['healRate']) prov_showHeal = list(Province['showHeal']) prov_importedCase = list(Province['importedCase']) prov_name = list(Province['name']) line_prov=\ ( Line() .add_xaxis(xaxis_data=prov_name)#xaxis_data为x轴,y_axis为y轴 .add_yaxis(series_name='现有确诊',y_axis=prov_nowConfirm,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='累计确诊',y_axis=prov_confirm,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='疑似病例',y_axis=prov_suspect,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡病例',y_axis=prov_dead,label_opts=opts.LabelOpts(is_show=False))#数据值得不显示 .add_yaxis(series_name='治愈病例',y_axis=prov_heal,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='showHeal',y_axis=prov_showHeal,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='境外输入病例',y_axis=prov_importedCase,label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国各省市总体疫情信息',pos_left='37%',pos_top='5%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='人数')) )#创建折线图 line_prov_rate=\ ( Line() .add_xaxis(xaxis_data=prov_name) .add_yaxis(series_name='治愈率',y_axis=prov_healRate,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name= '死亡率',y_axis=prov_deadRate,label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国各省市(区)治疗率、死亡率'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='百分比')) ) # line_prov_rate.render(savaPath+'\\prov_rate.html')#将生成的图像保存为html文件并存放在analisis文件夹 # line_prov.render(savaPath+'\\province.html')#将生成的图像保存为html文件并存放在analisis文件夹 page.add(line_prov) #将图像加入同一页 page.add(line_prov_rate) #将图像加入同一页 """利用pyecharts散点图对中国的历史数据做可视化,可以看出新增确诊人数(newConfirm),累计确诊人数(confirm),疑似(suspect)人数达到峰值的日期都接近于2月17日前后, 随后都逐渐下降,,而累计确诊人数也在随后趋于平缓,治愈人数也在不断趋近去确诊人数,明显可以看出中国疫情防控取得了有效的成果。 """ if flag: dwf.write_to_file(savaPath + '/中国各省市总体疫情信息.txt', str(line_prov.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/中国各省市(区)治疗率、死亡率.txt', str(line_prov_rate.dump_options_with_quotes())) return line_prov, line_prov_rate
def bar_now(): bar = ( Bar() .add_xaxis(list(data_pro_newly.name)) .add_yaxis("中国各省今日新增疫情情况", list(data_pro_newly.confirm)) .set_global_opts( title_opts=opts.TitleOpts(title="中国各省今日新增疫情情况"), ) ) page.add(bar) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国各省今日新增疫情情况.txt', str(bar.dump_options_with_quotes())) return bar
def china_line(): lines = ( Line() # 生成line类型图表 .add_xaxis(list(data_tota.date)) # 添加x轴 .add_yaxis('确诊人数', list(data_tota.confirm), label_opts=opts.LabelOpts(is_show=True),is_smooth=True) .add_yaxis('死亡人数', list(data_tota.dead), label_opts=opts.LabelOpts(is_show=True),is_smooth=True) .add_yaxis('治愈人数', list(data_tota.heal), label_opts=opts.LabelOpts(is_show=True),is_smooth=True) .set_global_opts(title_opts=opts.TitleOpts(title='中国累计确诊人数线形图')) ) page.add(lines) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国累计确诊人数线形图.txt', str(lines.dump_options_with_quotes())) return lines
def Top10_confirm_country(): message = pd.DataFrame(pd.read_excel(readPath+'/世界总体疫情信息/世界总体疫情信息.xlsx')) # 获取当前工作路径下的data数据 message_sort = message.sort_values(axis=0, ascending=False, by=['confirm']) world_message = message_sort.head(10) country_name = list(world_message['name']) country_isUpdated = list(world_message['isUpdated']) country_confirmAdd = list(world_message['confirmAdd']) country_confirm = list(world_message['confirm']) country_dead = list(world_message['dead']) country_heal = list(world_message['heal']) country_nowConfirm = list(world_message['nowConfirm']) country_nowConfirmCompare = list(world_message['nowConfirmCompare']) country_ConfirmCompare = list(world_message['confirmCompare']) country_healCompare = list(world_message['healCompare']) country_deadCompare = list(world_message['deadCompare']) ##生成国外疫情严重程度排名前十国家疫情相关信息折线图 Line_World = ( Line() .add_xaxis(xaxis_data=country_name) # .add_yaxis(series_name='新增确诊',yaxis_data=world_confirmAdd) .add_yaxis(series_name='确诊', y_axis=country_confirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡', y_axis=country_dead, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈', y_axis=country_heal, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='现存确诊', y_axis=country_nowConfirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='新增', y_axis=country_confirmAdd, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='疫情严重程度排名前十国家', pos_left='50%', pos_top='10%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')) ) ##生成国外疫情严重程度排名前十国家疫情相关信息柱形图 Bar_World = ( Bar() .add_xaxis(xaxis_data=country_name) # .add_yaxis(series_name='新增确诊',yaxis_data=world_confirmAdd) .add_yaxis(series_name='确诊', yaxis_data=country_confirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡', yaxis_data=country_dead, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈', yaxis_data=country_heal, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='现存确诊', yaxis_data=country_nowConfirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='新增', yaxis_data=country_confirmAdd, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='国外疫情严重程度排名前十国家', pos_left='50%', pos_top='10%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')) ) # Line_World.render(savaPath + '\\疫情严重程度排名前十国家(折线图).html') # Bar_World.render(savaPath + '\\疫情严重程度排名前十国家(柱状图).html') if flag: dwf.write_to_file(savaPath + '/疫情严重程度排名前十国家(折线图).txt', str(Line_World.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/疫情严重程度排名前十国家(柱状图).txt', str(Bar_World.dump_options_with_quotes()))
def china_provinces_imports(): path1 = readPath + '/中国各省市疫情信息/广东.xlsx' a = pd.read_excel(path1, index=False) a = a[a['name'].isin(['境外输入'])] a['name'] = a['name'].replace('境外输入', '广东') path = readPath + '/中国各省市疫情信息' Filelist = [] for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) for i in Filelist: data1 = pd.read_excel(readPath + '/中国各省市疫情信息/%s' % (i), index=False) n = i[:-5] data1 = data1[data1['name'].isin(['境外输入'])] data1['name'] = data1['name'].replace('境外输入', n) a = pd.concat([data1, a], axis=0) # 显示所有列 pd.set_option('display.max_columns', None) china_imported = a.drop_duplicates(subset=['name'], keep='first') china_imported.index = range(len(china_imported)) china_imported = china_imported.sort_values(axis=0, ascending=True, by=['confirm']) # 将dataframe格式转换成相应的列表格式 china_imported_name = china_imported['name'] china_imported_name = list(china_imported_name) china_imported_confirm = china_imported['confirm'] china_imported_confirm = list(china_imported_confirm) china_imported_heal = china_imported['heal'] china_imported_heal = list(china_imported_heal) ##############画境外输入xy翻转柱状图########### bar = ( Bar(init_opts=opts.InitOpts(height='1000px')) .add_xaxis(china_imported_name) .add_yaxis("中国各省境外输入确诊病例", china_imported_confirm) .add_yaxis("中国各省境外输入治愈病例", china_imported_heal) .reversal_axis() .set_series_opts(label_opts=opts.LabelOpts(position="right")) .set_global_opts(title_opts=opts.TitleOpts(title="中国各省境外输入信息")) ) # bar.render(savaPath+ '\\中国各省境外输入信息.html', index=False) page.add(bar) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国各省境外输入信息.txt', str(bar.dump_options_with_quotes())) return bar
def analyse_Chinaeveryday(): Chian_day = pd.DataFrame( pd.read_excel(readPath + '/中国总体历史疫情信息/历史每日新增信息.xlsx')) #读取信息 CNday_date = list(Chian_day['date']) CNday_confirm = list(Chian_day['confirm']) CNday_suspect = list(Chian_day['suspect']) CNday_dead = list(Chian_day['dead']) CNday_heal = list(Chian_day['heal']) CNday_importedCase = list(Chian_day['importedCase']) CNday_infect = list(Chian_day['infect']) CNday_deadRate = list(Chian_day['deadRate']) CNday_healRate = list(Chian_day['healRate']) line_CNday=\ ( Line() .add_xaxis(xaxis_data=CNday_date)#xaxis_data为x轴,y_axis为y轴 .add_yaxis(series_name='确诊病例',y_axis=CNday_confirm,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='疑似病例',y_axis=CNday_suspect,label_opts=opts.LabelOpts(is_show=False))#数据值得不显示 .add_yaxis(series_name= '死亡病例',y_axis=CNday_dead,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈病例',y_axis=CNday_heal,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='境外输入病例',y_axis=CNday_importedCase,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='Infect',y_axis=CNday_infect,label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国每日新增信息'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='人数')) )#创建折线图 line_CNday_rate=\ ( Line() .add_xaxis(xaxis_data=CNday_date) .add_yaxis(series_name='死亡率',y_axis=CNday_deadRate,label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈率',y_axis=CNday_healRate,label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国每日治疗率、死亡率'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='百分比')) )#创建折线图 # line_CNday_rate.render(savaPath+'\\CNdayrate.html')#将生成的图像保存为html文件并存放在analisis文件夹 # line_CNday.render(savaPath+'\\Chinaeveryday.html')#将生成的图像保存为html文件并存放在analisis文件夹 page.add(line_CNday) #将图像加入同一页 page.add(line_CNday_rate) #将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国每日新增信息.txt', str(line_CNday.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/中国每日治疗率、死亡率.txt', str(line_CNday_rate.dump_options_with_quotes())) return line_CNday, line_CNday_rate """
def foregin_history_all(): path = readPath + '/各国历史疫情信息' path2 = savaPath + '/各国历史疫情信息' dwf.createFile(path2) Filelist = [] # 将当前文件夹内的所有表名存放此列表 for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) for i in Filelist: data = pd.read_excel(readPath + '/各国历史疫情信息/%s' % (i), index=False) n = i[:-5] # 只提取国家名,不要后缀(.xlsx) y1_confirm = data['confirm'] y2_confirm_add = data['confirm_add'] y3_heal = data['heal'] y4_dead = data['dead'] date_list = [] for j in data['date']: date_list.append(j) x = date_list lines = ( Line() .add_xaxis(xaxis_data=x) .add_yaxis(series_name='确诊人数', y_axis=y1_confirm, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='增加确诊人数', y_axis=y2_confirm_add, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='治愈人数', y_axis=y3_heal, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='死亡人数', y_axis=y4_dead, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .set_global_opts(title_opts=opts.TitleOpts(title="%s" % (n) + "疫情走势", subtitle="数据来源:腾讯新闻"), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=10, interval=3))) ) # lines.render(savaPath + '\\daliy_changes_view\\各国历史疫情信息\\%s.html' % (n), index=False) if flag: dwf.write_to_file(savaPath + '/各国历史疫情信息/%s.txt' % (n),str(lines.dump_options_with_quotes())) page.add(lines)
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 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 china_data_all(): Chian_day = pd.DataFrame(pd.read_excel(readPath+'/中国总体历史疫情信息/历史每日新增信息.xlsx')) # 读取信息 CNday_date = list(Chian_day['date']) CNday_confirm = list(Chian_day['confirm']) CNday_suspect = list(Chian_day['suspect']) CNday_dead = list(Chian_day['dead']) CNday_heal = list(Chian_day['heal']) CNday_importedCase = list(Chian_day['importedCase']) CNday_infect = list(Chian_day['infect']) CNday_deadRate = list(Chian_day['deadRate']) CNday_healRate = list(Chian_day['healRate']) line_CNday = ( Line() .add_xaxis(xaxis_data=CNday_date) # xaxis_data为x轴,y_axis为y轴 .add_yaxis(series_name='确诊', y_axis=CNday_confirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='疑似', y_axis=CNday_suspect, label_opts=opts.LabelOpts(is_show=False)) # 数据值得不显示 .add_yaxis(series_name='死亡', y_axis=CNday_dead, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈', y_axis=CNday_heal, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='境外输入', y_axis=CNday_importedCase, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='infect', y_axis=CNday_infect, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国每日新增信息', pos_left='50%', pos_top='10%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')) ) # 创建折线图 line_CNday_rate = ( Line() .add_xaxis(xaxis_data=CNday_date) .add_yaxis(series_name='治愈率', y_axis=CNday_healRate, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国每日治疗率', pos_left='50%', pos_top='10%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')) ) # 创建折线图 # line_CNday_rate.render(savaPath + '\\中国每日治疗率.html') # 将生成的图像保存为html文件并存放在photo文件夹 # line_CNday.render(savaPath + '\\中国每日新增信息.html') # 将生成的图像保存为html文件并存放在photo文件夹 if flag: dwf.write_to_file(savaPath + '/中国每日治疗率.txt',str(line_CNday_rate.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/中国每日新增信息.txt',str(line_CNday.dump_options_with_quotes())) page.add(line_CNday_rate) page.add(line_CNday)
def china_history_all(): China_all = pd.DataFrame(pd.read_excel(readPath+'/中国总体历史疫情信息/历史总体信息.xlsx')) # 读取信息 CNday_date = list(China_all['date']) CNday_confirm = list(China_all['confirm']) CNday_dead = list(China_all['dead']) CNday_heal = list(China_all['heal']) line_CNday = ( Line() .add_xaxis(xaxis_data=CNday_date) # xaxis_data为x轴,y_axis为y轴 .add_yaxis(series_name='确诊', y_axis=CNday_confirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡', y_axis=CNday_dead, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈', y_axis=CNday_heal, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='中国疫情历史总体信息', pos_left='50%', pos_top='10%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')) ) # 创建折线图 # line_CNday.render(savaPath + '\\中国疫情历史总体信息.html') # 将生成的图像保存为html文件并存放在photo文件夹 page.add(line_CNday) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国疫情历史总体信息.txt', str(line_CNday.dump_options_with_quotes())) return line_CNday
def ChinaMaptime(): data = pd.read_excel(savePath + '中国各省市(区)合成表.xlsx', index_col=False) data['date'] = str('2020/') + data['date'] data['date'] = pd.to_datetime(data['date']) data['date'] = pd.PeriodIndex(data['date'], freq='D') # 转换为时间 class_list = list(data['date'].drop_duplicates()) class_list = sorted(class_list) t1 = Timeline() for i in class_list: data1 = pd.read_excel(savePath + '中国时间轴/%s.xlsx' % (i), index=False) data_name = data1['country'] data_confirm = data1['confirm'] chinaMap = ( Map() .add("累计确诊", [list(z) for z in zip(data_name, data_confirm)], maptype="china") .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="{}中国累计确诊数据".format(i)), visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=[{"max": 0, "label": '0人', "color": "#FFFAFA"}, {"min": 1, "max": 9, "label": '1-9人', "color": "#F08080"}, {"min": 10, "max": 99, "label": '10-99人', "color": "#BC8F8F"}, {"min": 100, "max": 499, "label": '100-499人', "color": "#A52A2A"}, {"min": 500, "max": 999, "label": '500-999人', "color": "#B22222"}, {"min": 1000, "max": 9999, "label": '1000-9999人', "color": "#8B0000"}, {"min": 10000, "label": '10000人及以上', "color": "#800000"}]), ) ) t1.add(chinaMap, "".format(i)) path = savePath + '时间轴图像/' isExists = os.path.exists(path) # 判断当前目录是否有时间轴图像文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # t1.render(path+'中国总体疫情变化.html') if flag: dwf.write_to_file(path + '中国总体疫情变化.txt', str(t1.dump_options_with_quotes()))
def world_data_all(): ############################################### world_message = pd.DataFrame(pd.read_excel(readPath+'/世界总体疫情信息/世界总体疫情信息.xlsx')) # 获取当前工作路径下的data数据 data_gb = world_message.groupby(by='continent') ####将世界总体的信息以不同的洲进行分组 world_gb = data_gb.agg(np.sum) world_gb continent = ['亚洲', '其他', '北美洲', '南美洲', '大洋洲', '欧洲', '非洲'] world_continent = continent continent_isUpdated = list(world_gb['isUpdated']) continent_confirmAdd = list(world_gb['confirmAdd']) continent_confirm = list(world_gb['confirm']) continent_dead = list(world_gb['dead']) continent_heal = list(world_gb['heal']) continent_nowConfirm = list(world_gb['nowConfirm']) continent_nowConfirmCompare = list(world_gb['nowConfirmCompare']) continent_ConfirmCompare = list(world_gb['confirmCompare']) continent_healCompare = list(world_gb['healCompare']) continent_deadCompare = list(world_gb['deadCompare']) Line_World = ( Line() .add_xaxis(xaxis_data=world_continent) # .add_yaxis(series_name='新增确诊',yaxis_data=world_confirmAdd) .add_yaxis(series_name='确诊', y_axis=continent_confirm, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='死亡', y_axis=continent_dead, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='治愈', y_axis=continent_heal, label_opts=opts.LabelOpts(is_show=False)) .add_yaxis(series_name='现存确诊', y_axis=continent_nowConfirm, label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title='各大洲总信息', pos_left='50%', pos_top='10%'), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')) ) Pie_continent_confirm = ( Pie() .add(series_name='死亡', data_pair=[(i, j) for i, j in zip(world_continent, continent_dead)], rosetype='radius') # .add(series_name='确诊',data_pair=[(i,j) for i,j in zip(continent_continent,continent_confirm)]) ) Pie_continent_heal = ( Pie() .add(series_name='治愈', data_pair=[(i, j) for i, j in zip(world_continent, continent_heal)], rosetype='radius') ) Pie_continent_nowconfirm = ( Pie() .add(series_name='现存确诊', data_pair=[(i, j) for i, j in zip(world_continent, continent_nowConfirm)], rosetype='radius') ) # Pie_continent_confirm.render(savaPath + '\\daliy_changes_view\\各大洲确诊信息.html') # Pie_continent_heal.render(savaPath + '\\daliy_changes_view\\各大洲治愈信息.html') # Pie_continent_nowconfirm.render(savaPath + '\\daliy_changes_view\\各大洲现存确诊信息.html') # Line_World.render(savaPath + '\\daliy_changes_view\\各大洲总信息.html') if flag: dwf.write_to_file(savaPath + '/各大洲确诊信息.txt',str(Pie_continent_confirm.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各大洲治愈信息.txt',str(Pie_continent_heal.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各大洲现存确诊信息.txt',str(Pie_continent_nowconfirm.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各大洲总信息.txt',str(Line_World.dump_options_with_quotes())) page.add(Pie_continent_confirm) page.add(Pie_continent_heal) page.add(Pie_continent_nowconfirm) page.add(Line_World)
def foregin_city_all(): path = readPath + '/各国各地区疫情信息' path2 = savaPath + '/各国疫情严重程度排名前十地区信息' dwf.createFile(path2) Filelist = [] # 将当前文件夹内的所有表名存放此列表 for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) # 判断数据是否存在 def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) # 随机颜色生成用于制作南丁格尔玫瑰图 def randomcolor(kind): colors = [] for i in range(kind): colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] color = "" for i in range(6): color += colArr[random.randint(0, 14)] colors.append("#" + color) return colors for i in Filelist: page1 = Page() data = pd.read_excel(readPath + '/各国各地区疫情信息/%s' % (i), index=False) data_sort = data.sort_values(axis=0, ascending=False, by=['confirm']) data_message = data_sort.head(10) # 提取疫情严重程度排名前十地区的信息 n = i[:-5] # 只提取国家名,不要后缀(.xlsx) checknan(data_message['confirm']) checknan(data_message['heal']) checknan(data_message['dead']) y1_confirm = data_message['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_dead = data_message['dead'] y2_dead = list(y2_dead) y2_dead = [int(i) for i in y2_dead] y3_heal = data_message['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] name_list = [] for j in data_message['name']: name_list.append(j) x = name_list color_series = randomcolor(len(x)) # Bars = ( # Bar(init_opts=opts.InitOpts(width='1080px',height='700px')) # .add_xaxis(xaxis_data=x) # .add_yaxis(series_name='确诊人数', yaxis_data=y1_confirm) # ) #####画南丁格尔玫瑰图########## # 画出确诊人数的图 fig = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig.add("", [list(z) for z in zip(x, y1_confirm)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的确诊人数'), legend_opts=opts.LegendOpts(is_show=False)) fig.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num fig.set_colors(color_series) # 画出死亡人数的图 fig1 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig1.add("", [list(z) for z in zip(x, y2_dead)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig1.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的死亡人数'), legend_opts=opts.LegendOpts(is_show=False)) fig1.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num # 画出治愈人数的图 fig2 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig2.add("", [list(z) for z in zip(x, y3_heal)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig2.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的治愈人数'), legend_opts=opts.LegendOpts(is_show=False)) fig2.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}例', font_style='italic', font_weight='bold', font_family='Microsoft YaHei')) # b:province;c:num page1.add(fig) # 将图像加入同一页 page1.add(fig1) # 将图像加入同一页 page1.add(fig2) # 将图像加入同一页 page1.render(savaPath + '/各国疫情严重程度排名前十地区信息/%s.html' % (n), index=False) if flag: dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(确诊)%s.txt' % (n),str(fig.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(死亡)%s.txt' % (n),str(fig1.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(治愈)%s.txt' % (n),str(fig2.dump_options_with_quotes()))
def china_citys_history(): page1 = Page() dwf.createFile(savaPath+'/中国各省的城市历史疫情信息') path = readPath + '中国各省的城市历史疫情信息' floder = glob.glob(os.path.join(path, "*")) # 判断数据是否存在 def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) for name in floder: for root, dirs, files in os.walk(name, topdown=False): for filename in files: name = ''.join('%s' % id for id in name) # print(type(filename)) # print(type(name)) filepath = name + '/' + filename filepath = filepath.replace('\\','/') data = pd.read_excel(filepath, index=False) province_name = re.findall('([\u4e00-\u9fa5]*)\\\\[\u4e00-\u9fa5]*\.xlsx', filepath) province_name = ''.join('%s' % id for id in province_name) city_name = re.findall('([\u4e00-\u9fa5]*)\.xlsx', filepath) city_name = ''.join('%s' % id for id in city_name) # print(province_name+'and'+city_name) checknan(data['confirm']) checknan(data['confirm_add']) checknan(data['heal']) checknan(data['dead']) y1_confirm = data['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_confirm_add = data['confirm_add'] y2_confirm_add = list(y2_confirm_add) y2_confirm_add = [int(i) for i in y2_confirm_add] y3_heal = data['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] y4_dead = data['dead'] y4_dead = list(y4_dead) y4_dead = [int(i) for i in y4_dead] date_list = [] for j in data['date']: date_list.append(j) x = date_list lines = ( Line() .add_xaxis(xaxis_data=x) .add_yaxis(series_name='确诊人数', y_axis=y1_confirm, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='增加确诊人数', y_axis=y2_confirm_add, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='治愈人数', y_axis=y3_heal, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='死亡人数', y_axis=y4_dead, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (city_name) + "疫情走势", subtitle="数据来源:腾讯新闻"), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=10, interval=3))) ) name1 = name.replace('data/中国各省的城市历史疫情信息\\', 'data/data_DaliyChangeView/中国各省的城市历史疫情信息/') dwf.createFile(name1) save_path = name1 + '%s.txt' # lines.render(save_path % (city_name), index=False) page1.add(lines) # 将图像加入同一页 if flag: dwf.write_to_file(save_path % (city_name), str(lines.dump_options_with_quotes())) page.render(savaPath + '/中国各省的城市历史疫情信息/analyse_all.html')
def analyse_worldhistory(): world = pd.DataFrame(pd.read_excel(readPath + '/世界总体疫情信息/世界总体疫情信息.xlsx')) confirmAdd = int(world['confirmAdd'].sum()) confirm = int(world['confirm'].sum()) confirmAddCut = int(world['confirmAddCut'].sum()) suspect = int(world['suspect'].sum()) dead = int(world['dead'].sum()) heal = int(world['heal'].sum()) nowConfirm = int(world['nowConfirm'].sum()) confirmCompare = int(world['confirmCompare'].sum()) nowConfirmCompare = int(world['nowConfirmCompare'].sum()) healCompare = int(world['healCompare'].sum()) deadCompare = int(world['deadCompare'].sum()) healRate = round(heal / confirm * 100, 2) deadRate = round(dead / confirm * 100, 2) aliveRate = round(100 - healRate - deadRate, 2) ratedata = [deadRate, healRate, aliveRate] ratecolumns = ['死亡率/% ', '治愈率/% ', '存活率/% '] bar_world=\ ( Bar() .add_xaxis(" ") .add_yaxis('新增确诊',[confirmAdd],color='pink',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('累计确诊',[confirm],color='green',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('疑似病例',[suspect],color='black',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('死亡病例',[dead],color='orange',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('治愈病例',[heal],color='red',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('现有确诊',[nowConfirm],color='grey',label_opts=opts.LabelOpts(is_show=True)) .set_global_opts(title_opts=opts.TitleOpts(title='世界疫情信息'), tooltip_opts=opts.TooltipOpts(is_show=False), xaxis_opts=opts.AxisOpts(name='日期',axislabel_opts={"interval":"0"}), yaxis_opts=opts.AxisOpts(name='人数',splitline_opts=opts.SplitLineOpts(is_show=True),) ) )#柱形图 bar_worldother=\ ( Bar() .add_xaxis(" ") .add_yaxis('confirmAddCut',[confirmAddCut],color='pink',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('confirmCompare',[confirmCompare],color='green',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('nowConfirmCompare',[nowConfirmCompare],color='orange',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('healCompare',[healCompare],color='black',label_opts=opts.LabelOpts(is_show=True)) .add_yaxis('deadCompare',[deadCompare],color='red',label_opts=opts.LabelOpts(is_show=True)) .set_global_opts(title_opts=opts.TitleOpts(title='世界疫情其他信息',pos_left='37%',pos_top='5%'), tooltip_opts=opts.TooltipOpts(is_show=False), xaxis_opts=opts.AxisOpts(name='日期',axislabel_opts={"interval":"0"}), yaxis_opts=opts.AxisOpts(name='人数',splitline_opts=opts.SplitLineOpts(is_show=True),) ) ) #柱形图 pie_worldrate=\ ( Pie() .add("", [list(z) for z in zip(ratecolumns,ratedata)], radius=["20%", "60%"], center=["55%", "50%"], rosetype="area" ) .set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="inside", font_size=12,formatter="{b}:{c}", font_style="italic",font_weight="bold", font_family="Microsoft YaHei"),) .set_global_opts(title_opts=opts.TitleOpts(title='世界总的死亡率、治疗率、存活率'), tooltip_opts=opts.TooltipOpts(axis_pointer_type= 'cross'), xaxis_opts=opts.AxisOpts(name='日期'), yaxis_opts=opts.AxisOpts(name='百分比')) )#饼图 page.add(bar_world) #添加到同一页面 page.add(bar_worldother) #添加到同一页面 page.add(pie_worldrate) #添加到同一页面 # bar_world.render(savaPath+'\\world.html')#在analysis生成html文件 # bar_worldother.render(savaPath+'\\worldother.html')#在analysis生成html文件 # pie_worldrate.render(savaPath+'\\worldrate.html')#在analysis生成html文件 """ 从图可以看出,国外疫情形势格外严峻,确诊人数高达150多万,死亡人数更是接近16万,存活率为67.86%。 其中发达国家的新冠确诊患者的人数相较于其他国家和地区会高出很多,伴随着国外疫情形势的加剧, 国内境外输入确诊的人数也在不断增加,在确保在外公民的安全和国内疫情能够持续稳定的前提下,需要加强对出入境人员的防控。 """ if flag: dwf.write_to_file(savaPath + '/世界疫情信息.txt', str(bar_world.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/世界疫情其他信息.txt', str(bar_worldother.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/世界总的死亡率、治疗率、存活率.txt', str(pie_worldrate.dump_options_with_quotes())) return bar_world, bar_worldother, pie_worldrate
def china_provinces_history(): page1 = Page() path2 = savaPath + '/中国各省市历史疫情信息' dwf.createFile(path2) path = readPath + '/中国各省市历史疫情信息' Filelist = [] for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) # print(Filelist) def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) for i in Filelist: data = pd.read_excel(readPath + '/中国各省市历史疫情信息/%s' % (i), index=False) n = i[:-5] checknan(data['confirm']) checknan(data['confirm_add']) checknan(data['heal']) checknan(data['dead']) y1_confirm = data['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_confirm_add = data['confirm_add'] y2_confirm_add = list(y2_confirm_add) y2_confirm_add = [int(i) for i in y2_confirm_add] y3_heal = data['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] y4_dead = data['dead'] y4_dead = list(y4_dead) y4_dead = [int(i) for i in y4_dead] date_list = [] for j in data['date']: date_list.append(j) x = date_list linse12 = ( Line() .add_xaxis(xaxis_data=x) .add_yaxis(series_name='确诊人数', y_axis=y1_confirm, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='增加确诊人数', y_axis=y2_confirm_add, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='治愈人数', y_axis=y3_heal, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .add_yaxis(series_name='死亡人数', y_axis=y4_dead, is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max"), ])) .set_global_opts(title_opts=opts.TitleOpts(title="%s" % (n) + "疫情走势", subtitle="数据来源:腾讯新闻"), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=10, interval=3))) ) # lines.render(savaPath + '\\daliy_changes_view\\中国各省市历史疫情信息\\%s.html' % (n), index=False) page1.add(linse12) # 将图像加入同一页 if flag: dwf.write_to_file(savaPath + '/中国各省市历史疫情信息/%s.txt' % (n), str(linse12.dump_options_with_quotes())) page.render(savaPath + '/中国各省市历史疫情信息/analyse_all.html')
def ProvincecityMap(): # 画出所有地区的累计确诊、疑似病例、新增确诊等6个特征的地理图(其实我也不想画那么多的,555)。 path = readPath + '中国各省市疫情信息/' path1 = savePath + '中国各省市疫情信息' isExists = os.path.exists(path1) # 判断当前目录是否有中国各省市(区)疫情信息文件夹,如果没有则创建 if not isExists: os.mkdir(path1) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 Filelist = [] for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) for i in Filelist: if i == '北京' or i == '上海' or i == '重庆' or i == '天津' or i == '澳门' or i == '香港': data = pd.read_excel(path + '%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['confirm'] for z in data_name1: z = z + str('区') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "累计确诊数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/累计确诊/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # chinaMap.render('world_map_view/中国各省市疫情信息/累计确诊/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) else: data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['confirm'] for z in data_name1: z = z + str('市') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "确诊数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/累计确诊/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render(path+'%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) for i in Filelist: if i == '北京' or i == '上海' or i == '重庆' or i == '天津' or i == '澳门' or i == '香港': data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['nowConfirm'] for z in data_name1: z = z + str('区') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "新增确诊数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/新增确诊/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render(path+'%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) else: data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['nowConfirm'] for z in data_name1: z = z + str('市') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "新增确诊数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/新增确诊/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/新增确诊/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) for i in Filelist: if i == '北京' or i == '上海' or i == '重庆' or i == '天津' or i == '澳门' or i == '香港': data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['suspect'] for z in data_name1: z = z + str('区') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "疑似病例数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/疑似病例/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/疑是病例/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) else: data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['suspect'] for z in data_name1: z = z + str('市') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "疑似病例数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/疑是病例/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/疑是病例/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) for i in Filelist: if i == '北京' or i == '上海' or i == '重庆' or i == '天津' or i == '澳门' or i == '香港': data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['dead'] for z in data_name1: z = z + str('区') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "累计死亡数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/累计死亡/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/累计死亡/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) else: data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['dead'] for z in data_name1: z = z + str('市') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "累计死亡数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/累计死亡/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/累计死亡/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) for i in Filelist: if i == '北京' or i == '上海' or i == '重庆' or i == '天津' or i == '澳门' or i == '香港': data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['heal'] for z in data_name1: z = z + str('区') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "累计治愈数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/累计治愈/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/累计治愈/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) else: data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['heal'] for z in data_name1: z = z + str('市') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "累计治愈数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/累计治愈/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/累计治愈/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) for i in Filelist: if i == '北京' or i == '上海' or i == '重庆' or i == '天津' or i == '澳门' or i == '香港': data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['importedCase'] for z in data_name1: z = z + str('区') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "境外输入数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/境外输入/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/境外输入/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes())) else: data = pd.read_excel(readPath + '中国各省市疫情信息/%s' % (i), index_col=False) data.columns data_name1 = data['name'] data_name = [] data_confirm = data['importedCase'] for z in data_name1: z = z + str('市') data_name.append(z) j = i[:-5] chinaMap = ( Map() .add("", [list(z) for z in zip(data_name, data_confirm)], maptype=j) .set_global_opts( title_opts=opts.TitleOpts(title="%s" % (j) + "境外输入数据"), visualmap_opts=opts.VisualMapOpts(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人及以上'}]), ) ) path = savePath + '中国各省市疫情信息/境外输入/' isExists = os.path.exists(path) # 判断当前目录是否有各国历史信息文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # chinaMap.render('world_map_view/中国各省市疫情信息/境外输入/%s' % (j)+'.html') if flag: dwf.write_to_file(path + '%s' % (j) + '.txt', str(chinaMap.dump_options_with_quotes()))