栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python3监控疫情的完整代码

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python3监控疫情的完整代码

具体代码如下所示:

import requests
import json
from pyecharts.charts import Map, Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType, RenderType
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5'
datas = json.loads(requests.get(url=url).json()['data'])
china = datas['areaTree'][0]['children']
data = []
for i in range(len(china)):
data.append([china[i]['name'], china[i]['total']['/confirm/i']])
confirm = datas['chinaTotal']['/confirm/i']
suspect = datas['chinaTotal']['suspect']
dead = datas['chinaTotal']['dead']
heal = datas['chinaTotal']['heal']
lastUpdateTime = datas['lastUpdateTime']
print(/confirm/i, suspect, dead, lastUpdateTime)
china_total = "确诊:" + str(/confirm/i) + " 疑似:" + str(suspect) + " 死亡:" + str(dead) + " 治愈:" + str(
heal) + " 更新日期:" + lastUpdateTime
geo = (
Geo(init_opts=opts.InitOpts(width="1200px", height="600px", bg_color="#404a59", page_title="全国疫情实时报告",
renderer=RenderType.SVG, theme="white")) # 设置绘图尺寸,背景色,页面标题,绘制类型
.add_schema(maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="rgb(49,60,72)",
border_color="rgb(0,0,0)")) # 中国地图,地图区域颜色,区域边界颜色
.add(series_name="geo", data_pair=data, type_=GeoType.EFFECT_SCATTER) # 设置地图数据,动画方式为涟漪特效effect scatter
.set_series_opts( # 设置系列配置
label_opts=opts.LabelOpts(is_show=False), # 不显示Label
effect_opts=opts.EffectOpts(scale=6)) # 设置涟漪特效缩放比例
.set_global_opts( # 设置全局系列配置
# visualmap_opts=opts.VisualMapOpts(min_=0, max_=sum / len(datas)), # 设置视觉映像配置,最大值为平均值
title_opts=opts.TitleOpts(title="全国疫情地图", subtitle=china_total, pos_left="center", pos_top="10px",
title_textstyle_opts=opts.TextStyleOpts(color="#fff")),
# 设置标题,副标题,标题位置,文字颜色
legend_opts=opts.LegendOpts(is_show=False), # 不显示图例
)
)
geo.render(path="./render.html")

运行的效果图

总结

以上所述是小编给大家介绍的Python3监控疫情的完整代码,希望对大家有所帮助,也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/21225.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号