在这里插入代码片
```from pyecharts.charts import Map, Geo
from pyecharts import options as opts
import requests
import json
# &callback=jQuery35109954929483789403_1605576147763&_=1605576147764
res = requests.get('https://i.snssdk.com/toutiao/normandy/pneumonia_trending/city_dist/?activeWidget=1')
res_json = res.json()['data']
res_name = res_json["list"]
res_sj = {}
for i in res_name:
res_sj[i["name"]] = i["total"]
data = [list(i) for i in zip(res_sj.keys(), res_sj.values())]
# data = [("广东", 10430.03), ("山东", 9579.31), ("河南", 9402.36), ("四川", 8041.82), ("江苏", 7865.99), ("河北", 7185.42),
# ("湖南", 6568.37), ("安徽", 5950.1), ("浙江", 5442), ("湖北", 5723.77), ("广西", 4602.66), ("云南", 4596.6),
# ("江西", 4456.74), ("辽宁", 4374.63), ("黑龙江", 3831.22), ("陕西", 3732.74), ("山西", 3571.21), ("福建", 3552),
# ("重庆", 2884), ("贵州", 3476.65), ("吉林", 2746.22), ("甘肃", 2557.53), ("内蒙古", 2470.63), ("上海", 2301.391),
# ("台湾", 2316.2), ("新疆", 2181.33), ("北京", 1961.2), ("天津", 1293.82), ("海南", 867.15), ("香港", 709.76),
# ("青海", 562.67), ("宁夏", 630.14), ("西藏", 300.21), ("澳门", 55.23)]
Testmap = (
Map().add("", data, "china")
.set_global_opts(
title_opts=opts.TitleOpts(title="疫情地图", subtitle="数据来源:字节跳动", pos_right="center", pos_top="5%"),
visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
pieces=[
{"min": 1, "max": 9, "label": "1-9人", "color": "green"},
{"min": 10, "max": 99, "label": "10-99人", "color": "yellow"},
{"min": 100, "max": 999, "label": "100-999人", "color": "red"}
]),
)
)
Testmap.render("testMap.html")
python地图学习
最新推荐文章于 2024-05-09 13:37:27 发布