写代码获取全国疫情地图
生活随笔
收集整理的這篇文章主要介紹了
写代码获取全国疫情地图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天在朋友圈看到一個同學寫的python獲取全國疫情地圖,我覺得挺有意思的,這個分享給大家,如果喜歡python的,可以通過這個作為入門手段。
1、安裝python
看這個鏈接來安裝,非常的小白
https://www.liaoxuefeng.com/wiki/1016959663602400/1016959856222624
2、獲取代碼
代碼是這位小哥寫的,我是拿來主義,我把代碼上傳了github,鏈接如下。
https://github.com/weiqifa0/yiqingditu
import time import json import requests import jsonpath from pyecharts.charts import Map import pyecharts.options as opts# 全國疫情地區分布(各省確診病例) def catch_cn_disease_dis():timestamp = '%d'%int(time.time()*1000)url_area = ('https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5''&callback=&_=') + timestampworld_data = json.loads(requests.get(url=url_area).json()['data'])china_data = jsonpath.jsonpath(world_data,expr='$.areaTree[0].children[*]')ls_province_names = jsonpath.jsonpath(china_data, expr='$[*].name')ls_confirm_vals = jsonpath.jsonpath(china_data, expr='$[*].total.confirm')ls_province_confirm = list(zip(ls_province_names, ls_confirm_vals,))return ls_province_confirm, world_datals_province_cfm, dic_world_data = catch_cn_disease_dis() print(ls_province_cfm)# 繪制全國疫情地圖 def map_cn_disease_dis() -> Map:c = (Map().add('中國', ls_province_cfm, 'china').set_global_opts(title_opts=opts.TitleOpts(title='全國新型冠狀病毒疫情地圖(確診數)'),visualmap_opts=opts.VisualMapOpts(is_show=True,split_number=6,is_piecewise=True, # 是否為分段型pos_top='center',pieces=[{'min': 10000, 'color': '#7f1818'}, #不指定 max{'min': 1000, 'max': 10000},{'min': 500, 'max': 999},{'min': 100, 'max': 499},{'min': 10, 'max': 99},{'min': 0, 'max': 5} ],),))return c map_cn_disease_dis().render('全國疫情地圖.html')3、運行
第一次運行的時候,肯定會出現有庫沒有安裝,直接運行 pip install xx
后面xx是你要安裝的庫的名字就好了,不要太簡單了。
4、運行
最后生產一個html,雙擊運行即可
掃碼或長按關注
回復「?籃球的大肚子」進入技術群聊
總結
以上是生活随笔為你收集整理的写代码获取全国疫情地图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决luyten 启动报错:this a
- 下一篇: Arm中国换帅风波始末 | 钛媒体深度