wmzhong

 

pyecharts模块实现数据可视化

 

这里采用疫情数据作为参考指标,绘画可视化视图。

 

1. 全球疫情累计死亡人数分布图

示例功能代码如下:

def yiqing_world(data):
    world_data = []
    for item in data["results"]:
        if item["countryEnglishName"]:
            world_data.append([item["countryEnglishName"]
                              .replace(\'United States of America\', \'United States\')
                              .replace(\'United Kingdom\', \'Greenland\'),
                              item["deadCount"]])

    _max = max([item[1] for item in world_data])

    world_map = (
        Map(init_opts=opts.InitOpts(theme=\'romantic\'))
        .add("累计死亡人数", world_data, \'world\', is_map_symbol_show=False)
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="全球疫情累计死亡人数分布图", pos_left="left"),
                         legend_opts=opts.LegendOpts(is_show=False),
                         visualmap_opts=opts.VisualMapOpts(max_=_max, is_piecewise=True)
                         )
    )
    world_map.render("全球疫情累计死亡人数分布图.html")

 

 

 2.中国疫情确诊人数分布地图

示例功能代码如下:

def yiqing_china(data):
    china_data = []
    for item in data["results"]:
        if item["countryName"] == "中国":
            china_data.append([item["provinceShortName"], item["confirmedCount"]])

    _max = max([item[1] for item in china_data])
    china_map = (
        Map(init_opts=opts.InitOpts(theme=\'dark\'))
        .add("确诊人数", china_data, "china", is_map_symbol_show=False)
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="中国疫情确诊人数分布地图"),
                         legend_opts=opts.LegendOpts(is_show=True),
                         visualmap_opts=opts.VisualMapOpts(max_=_max, is_piecewise=True)
                         )
    )
    china_map.render("中国疫情确诊人数分布地图.html")

 

此外还有更多绘画图。

 

 

 

 原文链接:https://www.jianshu.com/p/d0ec11363d2d

分类:

技术点:

相关文章:

  • 2021-03-31
  • 2022-12-23
  • 2021-12-02
  • 2021-05-07
  • 2022-12-23
  • 2021-07-23
  • 2021-10-29
  • 2021-07-11
猜你喜欢
  • 2021-12-18
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案