python可视化-疫情监控图(1)地图,柱形图
#需要导入的库
from pyecharts import options as opts from pyecharts.charts import Geo from pyecharts.globals import ChartType, SymbolType from pyecharts.charts import Map import pandas as pd from pyecharts.charts import Bar from pyecharts.globals import ThemeType from pyecharts.charts import Map,Page
数据集:https://www.cnblogs.com/qi-6666/p/15525301.html
或:https://files.cnblogs.com/files/blogs/673788/data.zip?t=1636387982&download=true
地图部分
# 设置列对齐 pd.set_option('display.unicode.ambiguous_as_wide', True) pd.set_option('display.unicode.east_asian_width', True) # 打开文件 df = pd.read_excel('china.xlsx') # 对省份进行统计 data2 = df['省份'] data2_list = list(data2) data3 = df['累计确诊'] data3_list = list(data3) data4 = df['死亡'] data4_list = list(data4) data5 = df ['治愈'] data5_list = list(data5) c = ( Map(init_opts=opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK)) .add("治愈", [list(z) for z in zip(data2_list, data5_list)], "china") .set_global_opts( title_opts=opts.TitleOpts(), visualmap_opts=opts.VisualMapOpts(max_=200), ) ) datamap=[list(z) for z in zip(data2_list, data4_list)] datamap pieces = [ {'max':1,'label':'0','color':'#F5D5C0','symbol':None}, {'min':1,'max':9,'latel':'1-9','color':'#F5AB7B'}, {'min':10,'max':99,'latel':'10-99','color':'#EC803A'}, {'min':100,'max':999,'latel':'100-999','color':'#F2632E'}, {'min':1000,'max':9999,'latel':'1000-9999','color':'#F0640A'}, {'min':10000,'label':'>=10000','color':'#E32721'} ] map=( Map(init_opts=opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK)) # Map() .add("死亡", maptype="china", data_pair=datamap, zoom=1.3, is_map_symbol_show=False ) .set_global_opts(#title_opts=opts.TitleOpts(title="死亡"), visualmap_opts=opts.VisualMapOpts(is_piecewise=True,pieces=pieces) ) .add("", maptype="china", data_pair=[['安徽',0],['江西',0],['重庆',0],['甘肃',0],['海南',0],['贵州',0],['宁夏',0],['青海',0],['西藏',0]], itemstyle_opts=opts.ItemStyleOpts(color="red") ) ) map.render_notebook()
柱形图部分
a2=data2['地区'] b2=data2['自愈'] c2=['英国','巴西','美国','印度'] d2=[140206,607125,764161,457221] d3=[39713,15268,84276,14323] # result = data.groupby(by=['地区','自愈']) from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.globals import ThemeType bar = ( Bar(init_opts=opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK)) .add_xaxis(c2) .add_yaxis('新增确诊',d3) .add_yaxis('死亡',d2) .set_colors([ '#76dd0f','#ff8080']) # .legend(loc='upper legt')#'#ff8080' .set_global_opts(visualmap_opts=opts.VisualMapOpts(pos_left='80%', pos_bottom=10, pos_right='30%')) .set_global_opts(title_opts=opts.TitleOpts(title="新确和死亡人数") ) ) bar.render_notebook()
最终结果(本页面只是一部分的代码,数据的爬取和其他图片的呈现请点击主页查看)
点赞关注后续更新