zoukankan      html  css  js  c++  java
  • 全疫情展示

    import requests
    import json
    from pyecharts import options as opts
    from pyecharts.charts import Map
    
    
    # 腾讯数据源
    url = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
    res = json.loads(requests.get(url).json()["data"])
    datas = res["areaTree"][0]["children"]
    # 全国数据做副标题
    china_total = "确诊:{} 疑似:{} 治愈:{} 死亡:{} 更新日期:{}".format(res["chinaTotal"]["confirm"],
                                                           res["chinaTotal"]["suspect"], res["chinaTotal"]["heal"],
                                                           res["chinaTotal"]["dead"], res["lastUpdateTime"])
    provinces = []
    confirm_value = []
    
    # 遍历获取各省份数据
    for data in datas:
        provinces.append(data["name"])
        confirm_value.append(data["total"]["confirm"])
    
    # 链式调用
    cmap = (
        Map(init_opts=opts.InitOpts(width="900px", height="700px", page_title="新型冠状病毒疫情地图"))
    
        # 在地图中插入数据,使用中国地图,隐藏标记
        .add("确诊", [list(z) for z in zip(provinces, confirm_value)], "china", is_map_symbol_show=False)
    
        # 设置坐标属性,显示省份名
        .set_series_opts(
            label_opts=opts.LabelOpts(is_show=True)
        )
    
        # 设置全局属性
        .set_global_opts(
            # 分段型数据,自定义分段
            visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=[
                {"min": 1000, "color": "#70161d"},
                {"min": 500, "max": 1000, "color": "#cb2a2f"},
                {"min": 100, "max": 500, "color": "#e55a4e"},
                {"min": 10, "max": 100, "color": "#f59e83"},
                {"min": 1, "max": 10, "color": "#fdebcf"}
            ]),
            # 标题
            title_opts=opts.TitleOpts(title="全国新型冠状病毒疫情地图", subtitle=china_total, pos_left="center", pos_top="10px"),
            # 不显示图例
            legend_opts=opts.LegendOpts(is_show=False),
            # 提示框
            tooltip_opts=opts.TooltipOpts(trigger_on="click", formatter='省份:{b}<br/>{a}:{c}')
        )
    )
    
    # 在 html 中渲染图表
    
    cmap.render()
    

      

  • 相关阅读:
    中国剩余定理(SCAUOJ 1077)
    uva 11426 GCD
    LA 4119 Always an integer (数论+模拟)
    uva 12003 Array Transformer (线段树套平衡树)
    uva 10253 Series-Parallel Networks (整数划分+多重集)
    LA 4123 Glenbow Museum
    uva 11361 Investigating Div-Sum Property
    2013多校训练赛第二场 总结
    uva 11174 Stand in a Line (排列组合)
    canvas 画椭圆
  • 原文地址:https://www.cnblogs.com/xk1013/p/13085518.html
Copyright © 2011-2022 走看看