Python笔记:用爬虫数据制作“全球各国在疫情中累计仙逝人数分布图”

折月煮酒 提交于 2020-08-12 07:38:35

代码:

import requests
from pyecharts.charts import *
from pyecharts import options as opts

url = "https://lab.isaaclin.cn/nCoV/api/area"
data = requests.get(url).json()
oversea_confirm = []
for item in data["results"]:
    if item["countryEnglishName"]:
        oversea_confirm.append((item["countryEnglishName"]
                                .replace("United States of America", "United States")
                                .replace("United Kiongdom", "United Kingdom"),
                                item["deadCount"]))
world_map = (
        Map(init_opts=opts.InitOpts(theme = "dark"))
        .add("累计死亡人数", oversea_confirm, "world",is_map_symbol_show = False, is_roam = False)
        .set_series_opts(label_opts=opts.LabelOpts(is_show = False, color = "#fff"))
        .set_global_opts(
            title_opts=opts.TitleOpts(title = "全球疫情累计仙逝人数分布图nntttttt制作者:哈佛在等我呢~"),
            legend_opts=opts.LegendOpts(is_show = False),
            visualmap_opts=opts.VisualMapOpts(max_ = 2700,
                                              is_piecewise = True,
                                              pieces=[
                                                {"max": 99999, "min": 10000, "label": "10000人及以上", "color": "#8A0808"},
                                                {"max": 9999, "min": 1000, "label": "1000-9999人", "color": "#B40404"},
                                                {"max": 999, "min": 500, "label": "500-999人", "color": "#DF0101"},
                                                {"max": 499, "min": 100, "label": "100-499人", "color": "#F78181"},
                                                {"max": 99, "min": 10, "label": "10-99人", "color": "#F5A9A9"},
                                                {"max": 9, "min": 0, "label": "1-9人", "color": "#FFFFCC"},
                                              ])
        )
    )
# world_map.render(path='全球疫情地图.html')
world_map.render_notebook()

运行结果:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!