Python3監(jiān)控疫情的完整代碼
更新時間:2020年02月20日 14:29:32 作者:丁典
這篇文章主要介紹了Python3監(jiān)控疫情的完整代碼,代碼簡單易懂,非常不錯具有一定的參考借鑒價值,需要的朋友可以參考下
具體代碼如下所示:
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']]) confirm = datas['chinaTotal']['confirm'] suspect = datas['chinaTotal']['suspect'] dead = datas['chinaTotal']['dead'] heal = datas['chinaTotal']['heal'] lastUpdateTime = datas['lastUpdateTime'] print(confirm, suspect, dead, lastUpdateTime) china_total = "確診:" + str(confirm) + " 疑似:" + 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)")) # 中國地圖,地圖區(qū)域顏色,區(qū)域邊界顏色 .add(series_name="geo", data_pair=data, type_=GeoType.EFFECT_SCATTER) # 設置地圖數(shù)據(jù),動畫方式為漣漪特效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監(jiān)控疫情的完整代碼,希望對大家有所幫助,也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
Python docx庫刪除復制paragraph及行高設置圖片插入示例
這篇文章主要為大家介紹了Python docx庫刪除復制paragraph及行高設置圖片插入操作實現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07pycharm不以pytest方式運行,想要切換回普通模式運行的操作
這篇文章主要介紹了pycharm不以pytest方式運行,想要切換回普通模式運行的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09MacOS(M1芯片?arm架構)下安裝tensorflow的詳細過程
這篇文章主要介紹了MacOS(M1芯片?arm架構)下如何安裝tensorflow,本節(jié)使用的版本是tensorflow2.4?python3.8,因此并未安裝加速插件,本文結合實例代碼詳細講解,需要的朋友可以參考下2023-02-02