爬取新冠肺炎疫情地图数据,绘制地理分布图
程序员文章站
2024-03-07 18:08:15
...
效果预览
爬取最新截止日期各个省累计确诊数据,并绘制地理分布图
代码实现
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import requests
#装了anaconda的可以pip install pyecharts安装pyecharts
from pyecharts.charts import Map,Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType,RenderType
# 绘图包参加网址https://pyecharts.org/#/zh-cn/geography_charts
url="https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp=requests.get(url)
html=resp.json()
data=json.loads(html["data"])
print(data["lastUpdateTime"])
china=data["areaTree"][0]["children"]
print(china)
china_total="确诊" + str(data["chinaTotal"]["confirm"])+ "疑似" + str(data["chinaTotal"]["suspect"])+ "死亡" + str(data["chinaTotal"]["dead"]) + "治愈" + str(data["chinaTotal"]["heal"]) + "更新日期" + data["lastUpdateTime"]
print(china_total)
data=[]
for i in range(len(china)):
data.append([china[i]["name"], china[i]["total"]["confirm"]])
print(data)
geo=Geo(init_opts=opts.InitOpts(width="1200px",height="600px",bg_color="#404a59",page_title="全国疫情实时报告",renderer=RenderType.SVG,theme="white"))
geo.add_schema(maptype="china",itemstyle_opts=opts.ItemStyleOpts(color="rgb(49,60,72)",border_color="rgb(0,0,0"))
geo.add("geo", data_pair=data, type_=GeoType.EFFECT_SCATTER)
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False),effect_opts=opts.EffectOpts(scale=6))
geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(min_=0,max_=349),title_opts=opts.TitleOpts(title="全国疫情地图",subtitle=china_total,pos_left="center",pos_top="10px"))
geo.render("render.html")#保存地理分布图
上一篇: php 三大特点:封装,继承,多态
下一篇: JavaWeb搭建网上图书商城毕业设计