数据分析---疫情数据可视化(地图)

  • 安装pyecharts库
  • 爬取所需要的数据(网上直接爬取数据)
  • 绘制全国地图
    • 绘制省份地图(以湖北省为例)
    • 在全国地图上加入湖北省数据
  • 导入数据(本地导入数据)
  • 获取代码

安装pyecharts库

pyecharts属于第三方库,需要从https://pypi.org/project/pyecharts/#files 手动下载安装
下载后,打开“Anaconda Command Prompt”

输入:pip install 所在路径+pyecharts-1.7.0-py3-none-any.whl

安装后可再输入:pip list
查看是否安装成功

import requests
import json
from pyecharts.charts import Map, Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType, RenderType

网上有很多博主的文章写的是from pyecharts import Map, Geo ;这是因为版本不同,现在需要加“.charts”

爬取所需要的数据(网上直接爬取数据)

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']])

注:今天犯了一个小错误,我在往列表中添加元素时,原来打成了data=data.append()结果报错“AttributeError: ‘NoneType’ object has no attribute ‘append’”,这是因为append会修改data本身,并且返回None。不能把返回值再赋值给data。

print(data)
[['湖北', 67786], ['广东', 1356], ['河南', 1273], ['浙江', 1227], ['湖南', 1018], ['安徽', 990], ['江西', 935], ['山东', 760], ['江苏', 631], ['重庆', 576], ['四川', 539], ['黑龙江', 482], ['北京', 437], ['上海', 350], ['河北', 318], ['福建', 296], ['广西', 252], ['陕西', 245], ['云南', 174], ['海南', 168], ['贵州', 146], ['香港', 137], ['天津', 136], ['山西', 133], ['甘肃', 129], ['辽宁', 125], ['吉林', 93], ['新疆', 76], ['宁夏', 75], ['内蒙古', 75], ['台湾', 50], ['青海', 18], ['澳门', 10], ['西藏', 1]]
confirm = datas['chinaTotal']['confirm']
suspect = datas['chinaTotal']['suspect']
dead = datas['chinaTotal']['dead']
heal = datas['chinaTotal']['heal']
lastUpdateTime = datas['lastUpdateTime']
print(confirm, suspect, dead, lastUpdateTime)
81017 147 3181 2020-03-14 10:03:41
china_total = "确诊:" + str(confirm) + " 疑似:" + str(suspect) + " 死亡:" + str(dead) + " 治愈:" + str(heal) + " 更新日期:" + lastUpdateTime
hubei = datas['areaTree'][0]['children'][0]['children']
print(hubei)
[{'name': '武汉', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 49991, 'suspect': 0, 'dead': 2436, 'deadRate': '4.87', 'showRate': False, 'heal': 35197, 'healRate': '70.41', 'showHeal': True}}, {'name': '孝感', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 3518, 'suspect': 0, 'dead': 126, 'deadRate': '3.58', 'showRate': False, 'heal': 3204, 'healRate': '91.07', 'showHeal': True}}, {'name': '黄冈', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 2907, 'suspect': 0, 'dead': 125, 'deadRate': '4.30', 'showRate': False, 'heal': 2720, 'healRate': '93.57', 'showHeal': True}}, {'name': '荆州', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 1580, 'suspect': 0, 'dead': 49, 'deadRate': '3.10', 'showRate': False, 'heal': 1464, 'healRate': '92.66', 'showHeal': True}}, {'name': '鄂州', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 1394, 'suspect': 0, 'dead': 55, 'deadRate': '3.95', 'showRate': False, 'heal': 1184, 'healRate': '84.94', 'showHeal': True}}, {'name': '随州', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 1307, 'suspect': 0, 'dead': 45, 'deadRate': '3.44', 'showRate': False, 'heal': 1181, 'healRate': '90.36', 'showHeal': True}}, {'name': '襄阳', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 1175, 'suspect': 0, 'dead': 38, 'deadRate': '3.23', 'showRate': False, 'heal': 1112, 'healRate': '94.64', 'showHeal': True}}, {'name': '黄石', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 1015, 'suspect': 0, 'dead': 38, 'deadRate': '3.74', 'showRate': False, 'heal': 938, 'healRate': '92.41', 'showHeal': True}}, {'name': '宜昌', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 931, 'suspect': 0, 'dead': 36, 'deadRate': '3.87', 'showRate': False, 'heal': 847, 'healRate': '90.98', 'showHeal': True}}, {'name': '荆门', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 928, 'suspect': 0, 'dead': 39, 'deadRate': '4.20', 'showRate': False, 'heal': 839, 'healRate': '90.41', 'showHeal': True}}, {'name': '咸宁', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 836, 'suspect': 0, 'dead': 14, 'deadRate': '1.67', 'showRate': False, 'heal': 816, 'healRate': '97.61', 'showHeal': True}}, {'name': '十堰', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 672, 'suspect': 0, 'dead': 8, 'deadRate': '1.19', 'showRate': False, 'heal': 626, 'healRate': '93.15', 'showHeal': True}}, {'name': '仙桃', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 575, 'suspect': 0, 'dead': 22, 'deadRate': '3.83', 'showRate': False, 'heal': 520, 'healRate': '90.43', 'showHeal': True}}, {'name': '天门', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 496, 'suspect': 0, 'dead': 15, 'deadRate': '3.02', 'showRate': False, 'heal': 476, 'healRate': '95.97', 'showHeal': True}}, {'name': '恩施州', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 252, 'suspect': 0, 'dead': 7, 'deadRate': '2.78', 'showRate': False, 'heal': 236, 'healRate': '93.65', 'showHeal': True}}, {'name': '潜江', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 198, 'suspect': 0, 'dead': 9, 'deadRate': '4.55', 'showRate': False, 'heal': 182, 'healRate': '91.92', 'showHeal': True}}, {'name': '神农架', 'today': {'confirm': 0, 'confirmCuts': 0, 'isUpdated': False}, 'total': {'confirm': 11, 'suspect': 0, 'dead': 0, 'deadRate': '0.00', 'showRate': False, 'heal': 11, 'healRate': '100.00', 'showHeal': True}}]
hubei_data = []
for j in range(len(hubei)):hubei_data.append([hubei[j]['name'], hubei[j]['total']['confirm']])
print(hubei_data)
[['武汉', 49991], ['孝感', 3518], ['黄冈', 2907], ['荆州', 1580], ['鄂州', 1394], ['随州', 1307], ['襄阳', 1175], ['黄石', 1015], ['宜昌', 931], ['荆门', 928], ['咸宁', 836], ['十堰', 672], ['仙桃', 575], ['天门', 496], ['恩施州', 252], ['潜江', 198], ['神农架', 11]]
hubeitotal = datas['areaTree'][0]['children'][0]['total']
hubei_confirm = hubeitotal['confirm']
hubei_suspect = hubeitotal['suspect']
hubei_dead = hubeitotal['dead']
hubei_heal = hubeitotal['heal']
print(hubei_confirm, hubei_suspect, hubei_dead, lastUpdateTime)
hubei_total = "确诊:" + str(hubei_confirm) + " 疑似:" + str(hubei_suspect) + " 死亡:" + str(hubei_dead) + " 治愈:" + str(hubei_heal) + " 更新日期:" + lastUpdateTime
print(hubei_total)
67786 0 3062 2020-03-14 10:03:41
确诊:67786 疑似:0 死亡:3062 治愈:51553 更新日期:2020-03-14 10:03:41

绘制全国地图

设置绘图尺寸,背景色,页面标题,绘制类型;
附上RGB颜色对照表:https://www.114la.com/other/rgb.htm

geo_china = Geo(init_opts=opts.InitOpts(width="1680px", height="800px", bg_color="#EAEAEA", page_title="全国疫情实时报告",renderer=RenderType.SVG, theme="white"))

选择地图板块,设置地图区域颜色、区域边界颜色

geo_china = geo_china.add_schema(maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="#FFFFFF",border_color="#030303"))

设置地图数据,动画方式为涟漪特效effect scatter

geo_china = geo_china.add(series_name="全国", data_pair=data, type_=GeoType.EFFECT_SCATTER)

设置系列配置;opts.LabelOpts(is_show=False/True)设置是否显示标签;effect_opts设置涟漪特效缩放比例

geo_china = geo_china.set_series_opts(label_opts=opts.LabelOpts(is_show=False),effect_opts=opts.EffectOpts(scale=6))

设置全局系列配置:设置标题,副标题,标题位置,文字颜色,opts.LegendOpts(is_show=True/False)设置“series_name”是否显示

geo_china = geo_china.set_global_opts(title_opts=opts.TitleOpts(title="全国疫情地图", subtitle=china_total,pos_left="center", pos_top="30px",title_textstyle_opts=opts.TextStyleOpts(color="#030303")),legend_opts=opts.LegendOpts(is_show=False))

绘制省份地图(以湖北省为例)

geo_hubei = (Geo(init_opts=opts.InitOpts(width="1200px", height="800px", bg_color="#EAEAEA", page_title="湖北省疫情实时报告",renderer=RenderType.SVG, theme="white")).add_schema(maptype="湖北", itemstyle_opts=opts.ItemStyleOpts(color="#FFFFFF",border_color="#030303")).add(series_name="湖北", data_pair=hubei_data, type_=GeoType.EFFECT_SCATTER).set_series_opts(label_opts=opts.LabelOpts(is_show=False),effect_opts=opts.EffectOpts(scale=6)).set_global_opts(title_opts=opts.TitleOpts(title="湖北省疫情地图", subtitle=hubei_total,pos_left="center", pos_top="30px",title_textstyle_opts=opts.TextStyleOpts(color="#030303")),legend_opts=opts.LegendOpts(is_show=False)))

在全国地图上加入湖北省数据

geo_chinahubei = geo_china.add(series_name="湖北", data_pair=hubei_data, type_=GeoType.EFFECT_SCATTER)
geo_chinahubei = geo_chinahubei.set_global_opts(title_opts=opts.TitleOpts(title="全国和湖北省疫情地图", subtitle=china_total,pos_left="center", pos_top="30px",title_textstyle_opts=opts.TextStyleOpts(color="#030303")),legend_opts=opts.LegendOpts(is_show=True))
geo_chinahubei = geo_chinahubei.set_series_opts(label_opts=opts.LabelOpts(is_show=False),effect_opts=opts.EffectOpts(scale=6))

导入数据(本地导入数据)

除了网上爬取数据还可以从本地直接读取已有数据

import xlrd
file = xlrd.open_workbook('F:\\公众号\\python\\【案例】数据分析---疫情数据可视化(地图)\\中国疫情数据.xlsx')
table = file.sheets()[0]
data = []
for i in range(1,len(table.col_values(0))):data.append([table.cell(i,0).value,table.cell(i,1).value])
print(data)
[['湖北', 67773.0], ['广东', 1353.0], ['河南', 1272.0], ['浙江', 1215.0], ['湖南', 1018.0], ['安徽', 990.0], ['江西', 935.0], ['山东', 759.0], ['江苏', 631.0], ['重庆', 576.0], ['四川', 539.0], ['黑龙江', 482.0], ['北京', 435.0], ['上海', 344.0], ['河北', 318.0], ['福建', 296.0], ['广西', 252.0], ['陕西', 245.0], ['云南', 174.0], ['海南', 168.0], ['贵州', 146.0], ['天津', 136.0], ['山西', 133.0], ['甘肃', 125.0], ['辽宁', 125.0], ['香港', 120.0], ['吉林', 93.0], ['新疆', 76.0], ['内蒙古', 75.0], ['宁夏', 75.0], ['台湾', 47.0], ['青海', 18.0], ['澳门', 10.0], ['西藏', 1.0]]

总结:
今天给大家分享了geo()的一些常用参数设置,如何设置画布、如何设置标题标签、如何设置动画效果,但是geo()中仍有很多参数并未涉及,这里也无法给大家一一展示,我从CSDN上找了两篇较为详细的geo()参数介绍,附在文末,感兴趣的朋友可以自行研究,在以后的可视化案例中,也会尽可能多使用其它参数进行展示。

参考博客:
https://blog.csdn.net/qq_22592457/article/details/98957767
https://blog.csdn.net/chunbali9596/article/details/100819631?depth_1-utm_source=distribute.pc_relevant_right.none-task&utm_source=distribute.pc_relevant_right.none-task

获取代码

以下是我的个人公众号,该篇的代码可在公众号中回复“疫情数据可视化”即可获得,谢谢大家支持。

数据分析---疫情数据可视化(地图)相关推荐

  1. pyecharts实践--2019-nCoV疫情数据可视化地图(实时更新)

    2019-nCoV疫情数据可视化地图效果如下: 获取数据(本文数据获取自腾讯的疫情实时追踪) 腾讯的疫情实时追踪网页: 点击查看. 这里我使用的是Google,追踪得到的数据如下图: 双击左边的 ge ...

  2. 新冠肺炎疫情数据可视化分析-FineBI

    目录 一.实验(实训)目的 二.实验(实训)原理或方法 三.仪器设备.材料 四.实验(实训)步骤 五.实训记录及结果 <------------------------------------- ...

  3. 对比3家平台,我总结了疫情数据可视化的8点经验

    www.pmcaff.com 本文为作者 吾某 于社区发布 开年以来,随着疫情方面的数据逐渐增多,一些互联网公司也纷纷发布一些可视化的数据产品服务,让用户可以实时并直观了解最新情况,可谓一个便民利器. ...

  4. mac mongodb可视化工具_github项目推荐|2019 冠状病毒疫情爬虫。疫情数据可视化

    ncov_2019_spider 2019 冠状病毒疫情爬虫.疫情数据可视化. 项目背景 疫情数据分析 数据来源 丁香医生,从1.24号开始采集入库,所以工程包含了24号后的数据. 数据展示 技术栈 ...

  5. 【Dash搭建可视化网站】项目10:疫情数据可视化大屏制作步骤详解

    疫情数据可视化大屏制作步骤详解 1 项目效果图 2 项目架构 3 文件介绍和功能完善 3.1 assets文件夹介绍 3.2 app.py和index.py文件完善 3.3 header.py文件完善 ...

  6. 疫情数据可视化-湖北省疫情可视化软件设计大赛作品

    湖北省疫情监测中心(疫情数据可视化)目录 前言 一.数据可视化 二.疫情可视化 湖北省疫情监测中心 ① 主要框架 ② 数据爬取 ③ 疫情可视化模块(疫情监测模块) ④ 便民信息可视化模块(检测信息模块 ...

  7. 【数据可视化】基于Dash制作的疫情数据可视化APP(Dash入门必读,附可运行源码)

    基于Dash制作的疫情数据可视化APP 在此之前,我写过一篇博客<基于Streamlit制作的时间序列数据分析APP>.Streamlit的优点是上手简单.能在短时间内快速构建具有一定交互 ...

  8. 可以搜python题答案的app-Python数据分析与数据可视化知到APP答案

    Python数据分析与数据可视化知到APP答案 更多相关问题 A.AsianB.AmericanC.EuropeanD.African 根据下列文章,请回答 31-35 题. New U.S Plan ...

  9. 毕业设计-基于Python爬虫的疫情数据可视化系统

    基于Python爬虫的疫情数据可视化系统 采用ECharts+Flask+Requests架构: 源码加3105088663

最新文章

  1. 【Flutter学习】组件学习之目录
  2. php oauth 服务端,OAuth 2.0 PHP客户端和服务器示例
  3. linux下vim 打开文件方式
  4. 三种编程命名规则(匈牙利法,小驼峰法,大驼峰法)
  5. oracle 创建nchar类型,nchar类型的用法!
  6. 原创 | 微服务网关 Kong 科普
  7. ros安装过后怎么找不到安装文件_ros配置乐视奥比中光相机
  8. python运维开发之第九天
  9. 【天梯选拔月赛】经典算法之过河问题+(倒水问题--见链接)
  10. 在GeoServer里设置图层的默认自定义样式,出现不显示预览图的情况(不起作用)...
  11. v​n​c​服​务​​安​装​与配置
  12. 如何解决More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations
  13. chmod 777和755
  14. 倾斜摄影三维模型五种常见格式
  15. python解析excel公式_读取Excel单元格值,而不是计算它的公式-openpyx
  16. java 安全策略_java.security.Security 支持的安全策略和算法
  17. 用WebView秒做一款简易的浏览器app
  18. 甲骨文java培训怎么样,Java岗
  19. 页面可用性之浏览器默认字体与CSS中文字体
  20. Elasticsearch Compound queries 学习总结

热门文章

  1. CSP-S(提高组)游记
  2. 软件测试架构师——众里寻她千百度
  3. GoogleMap获取地图中心点位置信息
  4. html 的页眉页脚,html – 带滚动条的页眉,页脚和内容的CSS布局
  5. 【优化理论与方法】线性规划的基本定理
  6. 《MySQL系列》MySQL详细入门教程
  7. IVMS-5000海康平台安装
  8. 【VUE】vue3学习笔记(异步组件,包含defineAsyncComponent、Suspense的使用)
  9. SAP MM ME57 把PR转成PO
  10. 极智AI | 目标检测实现分享二:听说克莱今天复出了?详解 YOLOv2 算法与克莱检测