最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python根據(jù)json數(shù)據(jù)畫疫情分布地圖的詳細(xì)代碼

 更新時(shí)間:2022年12月27日 11:33:54   作者:陽(yáng)862  
這篇文章主要介紹了python根據(jù)json數(shù)據(jù)畫疫情分布地圖的詳細(xì)代碼,掌握使用pyecharts構(gòu)建基礎(chǔ)的全國(guó)地圖可視化圖表,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

注:數(shù)據(jù)集在文章最后

一.基礎(chǔ)地圖使用

1.掌握使用pyecharts構(gòu)建基礎(chǔ)的全國(guó)地圖可視化圖表

演示

from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
map=Map()
data=[
    ("北京",99),
    ("上海",199),
    ("湖南",299),
    ("臺(tái)灣",199),
    ("安徽",299),
    ("廣州",399),
    ("湖北",599)
]
map.add("地圖",data,"china")
map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_show=True
 
    )
)
map.render("1.html")

結(jié)果是

這里有個(gè)問(wèn)題

 is_show=True表示展示圖例,但是不準(zhǔn)怎么辦?
這就需要手動(dòng)校準(zhǔn)范圍

from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts
map=Map()
data=[
    ("北京",99),
    ("上海",199),
    ("湖南",299),
    ("臺(tái)灣",199),
    ("安徽",299),
    ("廣州",399),
    ("湖北",599)
]
map.add("地圖",data,"china")
map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 9, "label": "1-9人", "color": "#CCFFFF"},
            {"min": 10, "max": 99, "label": "10-99人", "color": "#FFFF99"},
            {"min": 100, "max": 499, "label": "100-499人", "color": "#FF9966"},
            {"min": 500, "max": 999, "label": "500-999人", "color": "#FF6666"},
            {"min": 1000, "max": 9999, "label": "1000-9999人", "color": "#CC3333"},
            {"min": 10000, "label": "10000以上", "color": "#990033"},
 
        ]
 
    )
)
map.render("1.html")

結(jié)果是

 這樣就可以了

再解釋一下顏色的設(shè)置

這樣就可以查詢相應(yīng)的顏色

二.疫情地圖——國(guó)內(nèi)疫情地圖

1.案例效果

演示

 利用json在線在線解析工具可以看到

 那么我們就可以知道該怎么去提取

#從字典中取出省份數(shù)據(jù)
province_data_list=data_dict["areaTree"][0]["children"]

代碼

import json
from pyecharts.charts import Map
from pyecharts.options import *
#讀取文件
f=open("D:/疫情.txt","r",encoding="utf-8")
data=f.read()
#關(guān)閉文件
f.close()
#獲取各省數(shù)據(jù)
#將字符串json轉(zhuǎn)化為python的字典
data_dict=json.loads(data)
#從字典中取出省份數(shù)據(jù)
province_data_list=data_dict["areaTree"][0]["children"]
#組裝每個(gè)省份和確診人數(shù)為元組,并各個(gè)省的數(shù)據(jù)都封裝如列表
data_list=[]#繪圖需要用到數(shù)據(jù)列表
for province_data in province_data_list:
    province_name=province_data["name"]#省份名稱
    province_confirm=province_data["total"]["confirm"]#確診人數(shù)
    data_list.append((province_name,province_confirm))#這里注意列表里面嵌套的是元組
print(f"{type(data_list)}\n{data_list}")
 
#創(chuàng)建地圖對(duì)象
map=Map()
#添加數(shù)據(jù)
map.add("各省份確診人數(shù)",data_list,"china")
#設(shè)置全局配置,定制分段到1視覺(jué)映射
map.set_global_opts(
    title_opts=TitleOpts("全國(guó)疫情地圖",pos_left="center",pos_bottom="1%"),
    visualmap_opts=VisualMapOpts(
        is_show=True,#是否顯示
        is_piecewise=True,#是否分段
        pieces=[
            {"min": 1, "max": 9, "label": "1-9人", "color": "#CCFFFF"},
            {"min": 10, "max": 99, "label": "10-99人", "color": "#FFFF99"},
            {"min": 100, "max": 499, "label": "100-499人", "color": "#FF9966"},
            {"min": 500, "max": 999, "label": "500-999人", "color": "#FF6666"},
            {"min": 1000, "max": 9999, "label": "1000-9999人", "color": "#CC3333"},
            {"min": 10000, "label": "10000以上", "color": "#990033"},
 
        ]
 
    )
)
map.render("全國(guó)疫情地圖.html")

結(jié)果是

三.疫情地圖——省級(jí)疫情地圖

以河南省為例

代碼

import json
from pyecharts.charts import Map
from pyecharts.options import *
 
f=open("D:/疫情.txt","r",encoding="utf-8")
data=f.read()
#關(guān)閉文件
f.close()
#json數(shù)據(jù)轉(zhuǎn)化為python字典
data_dict=json.loads(data)
#取到河南省數(shù)據(jù)
cities_data=data_dict["areaTree"][0]["children"][3]["children"]
#準(zhǔn)備數(shù)據(jù)為元組并放入list
data_list=[]
 
for city_data in cities_data:
    city_name=city_data["name"]+"市"
    city_confirm=city_data["total"]["confirm"]
    data_list.append((city_name,city_confirm))
#構(gòu)建地圖
map=Map()
map.add("河南省疫情分布",data_list,"河南")
#設(shè)置全局選項(xiàng)
map.set_global_opts(
    title_opts=TitleOpts(title="河南疫情地圖"),
    visualmap_opts=VisualMapOpts(
        is_show=True,#是否顯示
        is_piecewise=True,#是否分段
        pieces=[
            {"min": 1, "max": 9, "label": "1-9人", "color": "#CCFFFF"},
            {"min": 10, "max": 99, "label": "10-99人", "color": "#FFFF99"},
            {"min": 100, "max": 499, "label": "100-499人", "color": "#FF9966"},
            {"min": 500, "max": 999, "label": "500-999人", "color": "#FF6666"},
            {"min": 1000, "max": 9999, "label": "1000-9999人", "color": "#CC3333"},
            {"min": 10000, "label": "10000以上", "color": "#990033"},
 
        ]
    )
)
map.render("河南疫情地圖.html")

結(jié)果是

有個(gè)問(wèn)題:濟(jì)源市因?yàn)閿?shù)據(jù)集中沒(méi)有相應(yīng)數(shù)據(jù),所以需要我們手動(dòng)加上去

這樣就可以了

結(jié)果是

 四.數(shù)據(jù)集

鏈接: https://pan.baidu.com/s/10eqeAEPjZC9PohlSnMOkJg?pwd=sjte 

提取碼: sjte 

到此這篇關(guān)于python根據(jù)json數(shù)據(jù)畫疫情分布地圖的詳細(xì)代碼的文章就介紹到這了,更多相關(guān)python畫疫情分布地圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

永寿县| 蒙城县| 微博| 布拖县| 南皮县| 宜阳县| 上蔡县| 平远县| 盐池县| 宝坻区| 油尖旺区| 大悟县| 泗阳县| 新巴尔虎左旗| 长宁区| 灌南县| 昌江| 东山县| 高尔夫| 红原县| 河北区| 阳信县| 达尔| 赤峰市| 中宁县| 安远县| 湖南省| 马龙县| 宿迁市| 上犹县| 义马市| 曲周县| 德安县| 休宁县| 修水县| 许昌县| 阿坝县| 红原县| 日喀则市| 耿马| 雅安市|