import requests, json
from pyecharts.charts import Map, Page, Pie, Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType def chinaTotal():
re = requests.get(
"https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=jQuery341045890055561903065_1592206473904&_=1592206473905")
data = str(re.text)[42:-1]
data = json.loads(data)
data = json.loads(data["data"])
print(data["chinaTotal"])
data = data["chinaTotal"]
confirm = data["confirm"]
heal = data["heal"]
dead = data["dead"]
nowConfirm = data["nowConfirm"]
suspect = data["suspect"]
nowSevere = data["nowSevere"]
importedCase = data["importedCase"]
noInfect = data["noInfect"]
print(
"confirm:" + str(confirm) + "\n"
"heal:" + str(heal) + "\n"
"dead:" + str(dead) + "\n"
"nowConfirm:" + str(nowConfirm) + "\n"
"suspect:" + str(
suspect) + "\n"
"nowSevere:" + str(nowSevere) + "\n"
"importedCase:" + str(importedCase) + "\n"
"noInfect:" + str(
noInfect) + "\n\n"
) def areatotal():
global province_distribution
re = requests.get(
"https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=jQuery341045890055561903065_1592206473904&_=1592206473905")
data = str(re.text)[42:-1]
data = json.loads(data)
data = data["data"]
data = json.loads(data)
data = data["areaTree"]
data = data[0]
data = data["children"]
print(data)
for i in data:
temp = []
areaname = str(i["name"])
nowConfirm = str(i["total"]["nowConfirm"])
confirm = str(i["total"]["confirm"])
suspect = str(i["total"]["suspect"])
dead = str(i["total"]["dead"])
deadRate = str(i["total"]["deadRate"])
heal = str(i["total"]["heal"])
healRate = str(i["total"]["healRate"])
temp.append(areaname)
temp.append(confirm)
kv.append(temp)
province_distribution[areaname] = province_distribution.get(areaname, confirm)
print(
"areaname:" + str(areaname) + "\n"
"nowConfirm:" + str(nowConfirm) + "\n"
"confirm:" + str(confirm) + "\n"
"suspect:" + str(
suspect) + "\n"
"dead:" + str(dead) + "\n"
"deadRate:" + str(deadRate) + "\n"
"heal:" + str(heal) + "\n"
"healRate:" + str(
healRate) + "\n\n" ) def initMap():
map = Map()
map.set_global_opts(
title_opts=opts.TitleOpts(title="中国疫情地图"),
visualmap_opts=opts.VisualMapOpts(max_=3600, is_piecewise=True,
pieces=[
{"max": 100000, "min": 10001, "label": ">10000", "color": "#680606"},
{"max": 10000, "min": 5001, "label": "5001-10000", "color": "#8A0808"},
{"max": 5000, "min": 1001, "label": "1001-5000", "color": "#B40404"},
{"max": 1000, "min": 600, "label": "600-1000", "color": "#DF0101"},
{"max": 599, "min": 100, "label": "100-599", "color": "#F78181"},
{"max": 99, "min": 1, "label": "1-99", "color": "#F5A9A9"},
{"max": 0, "min": 0, "label": "0", "color": "#FFFFFF"},
], ) # 最大数据范围,分段
)
pie = (
Pie() .add("", kv, center=["50%", "80%"], radius=[30, 100]) # 加入数据
.set_global_opts(title_opts=opts.TitleOpts(title="疫情统计饼图"),
legend_opts=opts.LegendOpts(pos_left=160)) # 全局设置项
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))) # 样式设置项
# V1 版本开始支持链式调用
# 你所看到的格式其实是 `black` 格式化以后的效果
# 可以执行 `pip install black` 下载使用
# Bar是柱状图/条形图 # 不习惯链式调用的开发者依旧可以单独调用方法
bar = Bar(init_opts=opts.InitOpts(bg_color='rgba(255,250,205,0.2)',
width='2000px',
height='600px',
page_title='page',
theme=ThemeType.ESSOS
))
bar.add_xaxis(xaxis_data=list(province_distribution.keys()))
bar.add_yaxis("感染总数", list(province_distribution.values()))
bar.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
bar.set_series_opts(markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(type_='max', name='最大值'), opts.MarkPointItem(type_='min', name='最小值')]))
bar.render(r"testBar.html")
map.add("中国疫情地图", data_pair=province_distribution.items(), maptype="china", is_roam=True)
page.add(map)
page.add(pie)
page.add(bar) if __name__ == '__main__':
province_distribution = {}
kv = []
chinaTotal()
areatotal()
page = Page()
initMap()
print(province_distribution)
page.render('中国疫情地图.html')

利用Python爬取疫情数据并使用可视化工具展示的更多相关文章

  1. 如何使用Python爬取基金数据,并可视化显示

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理 以下文章来源于Will的大食堂,作者打饭大叔 前言 美国疫情越来越严峻,大选也进入 ...

  2. python爬取旅游数据+matplotlib简单可视化

    题目如下: 共由6个函数组成: 第一个函数爬取数据并转为DataFrame: 第二个函数爬取数据后存入Excel中,对于解题来说是多余的,仅当练手以及方便核对数据: 后面四个函数分别对应题目中的四个m ...

  3. python爬取疫情数据详解

    首先逐步分析每行代码的意思: 这是要引入的东西: from os import path import requests from bs4 import BeautifulSoup import js ...

  4. python爬取疫情数据存入MySQL数据库

    import requests from bs4 import BeautifulSoup import json import time from pymysql import * def mes( ...

  5. 毕设之Python爬取天气数据及可视化分析

    写在前面的一些P话:(https://jq.qq.com/?_wv=1027&k=RFkfeU8j) 天气预报我们每天都会关注,我们可以根据未来的天气增减衣物.安排出行,每天的气温.风速风向. ...

  6. 利用python爬取58同城简历数据

    利用python爬取58同城简历数据 利用python爬取58同城简历数据 最近接到一个工作,需要获取58同城上面的简历信息(http://gz.58.com/qzyewu/).最开始想到是用pyth ...

  7. 利用python爬取城市公交站点

    利用python爬取城市公交站点 页面分析 https://guiyang.8684.cn/line1 爬虫 我们利用requests请求,利用BeautifulSoup来解析,获取我们的站点数据.得 ...

  8. 没有内涵段子可以刷了,利用Python爬取段友之家贴吧图片和小视频(含源码)

    由于最新的视频整顿风波,内涵段子APP被迫关闭,广大段友无家可归,但是最近发现了一个"段友"的app,版本更新也挺快,正在号召广大段友回家,如下图,有兴趣的可以下载看看(ps:我不 ...

  9. 利用Python爬取朋友圈数据,爬到你开始怀疑人生

    人生最难的事是自我认知,用Python爬取朋友圈数据,让我们重新审视自己,审视我们周围的圈子. 文:朱元禄(@数据分析-jacky) 哲学的两大问题:1.我是谁?2.我们从哪里来? 本文 jacky试 ...

随机推荐

  1. eclipse及idea使用问题记录(为了方便github同步,重新用Markdown写了一篇)

    使用eclipse或idea的时候会遇到各式各样的小问题,解决方案其实网上也大都搜得到,但是下次遇到的时候总是想不起来如何解决,还要花费时间再次查资料.所以以后把遇到的问题都记录一下. @ 目录 Ec ...

  2. Jmeter 常用函数(6)- 详解 __P

    如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦 https://www.cnblogs.com/poloyy/p/13291704.html 作用 和 __property 作用一样,不 ...

  3. Hyperledger Fabric【区块链学习一】

    Hyperledger Fabric 学习 什么是区块链 什么是区块链在我们没有接触的时候,只知道它是一个去中心化的存储方式.当我们发生交易,或者动作的时候我们会将记录通知给所有参与者共同维护,达到去 ...

  4. git 生成并添加 SSH key

    git config --global user.name "wangjunqiang" git config --global user.email "wangjunq ...

  5. random模块python

    random是用于生成随机数的,我们可以利用它随机生成数字或者选择字符串. random.random()    用于生成一个随机浮点数:range[0.0,1.0) ? 1 2 import ran ...

  6. Java异步CompletableFuture的使用

    所谓异步调用其实就是实现一个可无需等待被调用函数的返回值而让操作继续运行的方法.Java中的CompletableFuture 提供了四个静态方法来创建一个异步操作. public static Co ...

  7. Communication-Efficient Learning of Deep Networks from Decentralized Data

    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布! Proceedings of the 20th International Conference on Artificial Intell ...

  8. Oracle数据库教程-数据定义语言(表操作)

    创建表 建表语法: CREATE TABLE 表名 ( 列1 数据类型 [primary key], 列2 数据类型 default 默认值 [not null], …, constraint 约束名 ...

  9. Java方法传参,测试在方法内部改变参数内容是否会影响到原值

    我分了三种类型的参数进行测试 一.基本类型 public static void main(String[] args) { System.out.println("验证基本类型int作为参 ...

  10. Helix QAC/QAC++—代码静态测试工具介绍—符合功能安全标准MISRA ISO26262

    Helix QAC是静态代码分析工具,依据C和C++编码规则自动扫描代码对规则的违背.开发团队在开发过程的早期就可以用它来检测缺陷,因为此时修改代码是最方便也最经济的.Helix QAC因此自动化强制 ...