Exemplo n.º 1
0
def show_map_charts():
    city_num = df['city_dealed'].value_counts()
    city_num.drop('国外', inplace=True)
    city_num.drop('未填写', inplace=True)

    map1 = Map(init_opts=opts.InitOpts(width='1350px', height='750px'))
    map1.add("", [
        list(z) for z in zip(city_num.index.tolist(), city_num.values.tolist())
    ],
             maptype='china')
    map1.set_global_opts(title_opts=opts.TitleOpts(title='评论者国内城市分布'),
                         visualmap_opts=opts.VisualMapOpts(max_=50),
                         toolbox_opts=opts.ToolboxOpts())
    map1.render()
Exemplo n.º 2
0
 def map(self, datasets):
     print(datasets)
     m = Map(init_opts=opts.InitOpts(width="1100px", height="700px"))
     m.add("count", datasets, maptype="china")
     m.set_global_opts(
         title_opts=opts.TitleOpts(title=get_title()),
         visualmap_opts=opts.VisualMapOpts(
             max_=3000,
             min_=100,
             range_text=['High', 'Low'],
             is_calculable=True,
             range_color=["lightskyblue", "yellow", "orangered"]),
         legend_opts=opts.LegendOpts(is_show=False),
     ).render('docs/new-map.html')
Exemplo n.º 3
0
def map_visualmap(sequence, date) -> Map:
    c = Map()
    c.add(date, sequence, maptype="china")
    c.set_global_opts(title_opts=opts.TitleOpts(title="CBIC:全国各省现存确诊_至4月8号",subtitle="数据来源于丁香园"),legend_opts=opts.LegendOpts(is_show=False),visualmap_opts=opts.VisualMapOpts(is_piecewise=True,\
        pieces=pieces_list))
    # c = (
    #     Map()
    #     .add(date, sequence, maptype="china")
    #     .set_global_opts(
    #         title_opts=opts.TitleOpts(title="全国疫情动态地图_确诊累计人数_截至至3月14号"),
    #         visualmap_opts=opts.VisualMapOpts(max_=1400)
    #     )
    # )
    return c
Exemplo n.º 4
0
def get_map(labels, counts, where, title, size, pieces):
    my_map = Map(init_opts=opts.InitOpts(width=size[0], height=size[1]))
    my_map.add("新冠数据", [list(z) for z in zip(labels, counts)], where)
    my_map.set_series_opts(label_opts=opts.LabelOpts(font_size=8))
    my_map.set_global_opts(
        title_opts=opts.TitleOpts(title=title),
        legend_opts=opts.LegendOpts(is_show=False),
        visualmap_opts=opts.VisualMapOpts(
            pieces=pieces,
            is_piecewise=True,
            is_show=False
        ),
    )
    return my_map
def map_type():
    school_type_local = analysis_data.school_rank()
    c = Map()
    for key, value in school_type_local.items():
        c.add(key, list(value.iteritems()), "china")
    c.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
                                                        pieces=[
                                                            {
                                                                "min": 100,
                                                                "max": 250
                                                            },
                                                            {
                                                                "min": 30,
                                                                "max": 100
                                                            },
                                                            {
                                                                "min": 20,
                                                                "max": 30
                                                            },
                                                            {
                                                                "min": 10,
                                                                "max": 20
                                                            },
                                                            {
                                                                "min": 5,
                                                                "max": 10
                                                            },
                                                            {
                                                                "value": 4
                                                            },
                                                            {
                                                                "value": 3
                                                            },
                                                            {
                                                                "min": 2,
                                                                "max": 2
                                                            },
                                                            {
                                                                "value": 1,
                                                                "label":
                                                                '1 一枝独秀',
                                                                "color": 'grey'
                                                            },
                                                        ]),
                      title_opts=opts.TitleOpts(title='各类院校全国分布'),
                      legend_opts=opts.LegendOpts(type_="scroll",
                                                  pos_left="80%",
                                                  orient="vertical"))
    return c
def get_data():

    # API地址
    url = 'https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist'

    # 添加请求头
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400'
    }

    # 获取结果
    res = requests.get(url=url,  headers=headers).text
    # 转为json
    data = json.loads(res)
    # 获取数据
    name = jsonpath.jsonpath(data, '$..name')
    confirm = jsonpath.jsonpath(data, '$..confirm')
    # 配对
    data_list = zip(name, confirm)
    # print(list(data_list))

    # 绘制地图
    map = Map(init_opts=opts.InitOpts(width="1900px", height="900px", page_title="全球疫情分布图", bg_color="#ADD8E6", theme="white")).add(
        series_name='世界疫情分布图', data_pair=data_list, maptype='world', name_map=nameMap, is_map_symbol_show=False)

    # 设置系列配置项
    map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

    # 设置全局配置项
    # map.set_global_opts(title_opts=opts.TitleOpts(title="国外疫情情况"),
    # visualmap_opts=opts.VisualMapOpts(max_=2000000, is_piecewise=True))

    map.set_global_opts(title_opts=opts.TitleOpts(title="国外疫情情况"),
                        visualmap_opts=opts.VisualMapOpts(pieces=[
                            {"min": 500000, "color": "#800000"},
                            {"min": 100000, "max": 500000,
                                "color": "#CC0000"},
                            {"min": 50000, "max": 100000,
                                "color": "#FF0000"},
                            {"min": 10000, "max": 50000,
                                "color": "#FF4500"},
                            {"min": 1000, "max": 10000, "color": "#FF7F50"},
                            {"min": 100, "max": 1000, "color": "#FFA07A"},
                            {"max": 100, "color": "#FFCCCC"},
                        ],
        is_piecewise=True))  # 显示分段式图例

    # 生成文件
    map.render('世界疫情分布图.html')
Exemplo n.º 7
0
def get_map():
    maps = Map(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
    value = []
    for i in area:
        where = {
            'job_area': {
                '$regex': ".*" + i + ".*"
            },
        }
        count = mongodb.get_count_by_where(where)
        value.append((i + "区", count))
    maps.add("区域", value, "深圳")
    maps.set_global_opts(title_opts=opts.TitleOpts(title="岗位地区需求图", ),
                         legend_opts=opts.LegendOpts(pos_left="20%"))
    return (maps)
Exemplo n.º 8
0
 def analysis(self):
     """
     数据分析可视化
     :return:
     """
     data_list = [(i[0], i[3]) for i in self.result]
     with open('CountryMap.json', 'r') as f:
         country_map = json.load(f)
     map = Map(options.InitOpts(width='1366px', height='768px'))
     map.add("确诊病例", data_list, 'world', name_map=country_map, is_map_symbol_show=False)
     map.set_series_opts(label_opts=options.LabelOpts(is_show=False))
     map.set_global_opts(
         title_opts=options.TitleOpts(title='全球疫情数据可视化展示'),
         visualmap_opts=options.VisualMapOpts(max_=100000)
     )
     map.render('World_Epidemic_Analysis.html')
def map_cs_level():
    levels = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-']
    data = analysis_data.get_cs_level_formap()
    c = Map()
    for i in levels:
        c.add(i,
              data[i],
              "china",
              tooltip_opts=opts.TooltipOpts(
                  formatter=JsCode("""function (param) {
                        if (param.data) return param.data.value[1];
                        else return '无'
                    }""")))
    c.set_global_opts(legend_opts=opts.LegendOpts(selected_mode='single'),
                      title_opts=opts.TitleOpts(title="学科评估"))
    return c
Exemplo n.º 10
0
 def analysisArea(self, title='分析好友地域分布', friends_info=None):
     area_infos = {'未知': 0}
     for item in friends_info.get('province'):
         if not item: area_infos['未知'] += 1
         else:
             if item in area_infos: area_infos[item] += 1
             else: area_infos[item] = 1
     map_ = Map(init_opts=dict(theme='purple-passion', page_title=title))
     map_.add(title,
              data_pair=tuple(zip(area_infos.keys(), area_infos.values())),
              maptype='china')
     map_.set_global_opts(
         title_opts=opts.TitleOpts(title=title),
         visualmap_opts=opts.VisualMapOpts(max_=200),
     )
     map_.render(os.path.join(self.savedir, '%s.html' % title))
Exemplo n.º 11
0
 def get_map_base(self, _data):
     '''
     plot geo-VisualMap
     :param _data: gps对应的城市分布(dataframe)
     :return: 热点图
     '''
     register_url(self.echarts_url)
     c_map = Map(init_opts=opts.InitOpts(
         width="1000px", height="600px", page_title='', bg_color=''))
     c_map.add(series_name=self.series_name,
               data_pair=_data,
               maptype=self.country)
     c_map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
     c_map.set_global_opts(
         title_opts=opts.TitleOpts(title="Map-VisualMap"),
         visualmap_opts=opts.VisualMapOpts(max_=self.threshold_plot))
     return c_map
Exemplo n.º 12
0
def draw():
    get_data.GetCondition()
    result = {'province': [], 'province_confirmedCount': []}
    result['province'].append('台湾')
    result['province_confirmedCount'].append(18)
    result['province'].append('香港')
    result['province_confirmedCount'].append(56)
    result['province'].append('澳门')
    result['province_confirmedCount'].append(10)

    # 批量删除多余字符的函数
    def replace_something(source_str, replace_list):
        for line in replace_list:
            source_str = source_str.replace(line, "")
        return source_str

    with open("virus.csv", 'r', encoding='UTF-8') as csvFile:
        reader = csv.reader(csvFile)  # 读取文件数据
        for item in reader:
            if reader.line_num == 1:
                continue
            # 定义删除的字串列表
            replace_list = ['省', '市', '壮族自治区', '维吾尔自治区', '回族自治区', '自治区']
            # 调用删除字串的函数
            province_name = replace_something(item[0], replace_list)
            if len(result['province']) == 34:
                break
            if province_name in result['province']:
                continue
            else:
                result['province'].append(province_name)
                result['province_confirmedCount'].append(int(item[2]))
    # 绘制地图
    from pyecharts import options as opts
    from pyecharts.charts import Map

    map = Map()
    map.add("确诊人数", [
        list(z)
        for z in zip(result['province'], result['province_confirmedCount'])
    ], 'china')
    map.set_global_opts(
        title_opts=opts.TitleOpts(title="疫情地图"),
        visualmap_opts=opts.VisualMapOpts(max_=2000),
    )
    map.render(path="疫情地图.html")
Exemplo n.º 13
0
def plt_data(name, confirm_all):
    data_list = list(zip(name, confirm_all))
    map = Map(opts.InitOpts(width='1600px',
                            height='600px')).add(series_name='累计确诊',
                                                 data_pair=data_list,
                                                 maptype="china",
                                                 is_map_symbol_show=False)
    map.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
    map.set_global_opts(title_opts=opts.TitleOpts("中国疫情"),
                        visualmap_opts=opts.VisualMapOpts(
                            range_color=Faker.visual_color, max_=1000))  # 图例显示
    map.render("html/中国疫情分布图.html")
    plt.rcParams['font.sans-serif'] = ['FangSong']
    plt.bar(range(len(confirm_all)), confirm_all, tick_label=name)
    plt.xticks(rotation=270)
    plt.savefig("imgdata/中国疫情柱状图")
    print("中国数据可视化成功,文件名:中国疫情分布图.html、中国疫情柱状图.png")
Exemplo n.º 14
0
    def make_geo_map(self):
        """
        生成世界地图,根据各国电影发行量
        :return:
        """
        # print(get_current_time() + '|-------> 正在生成 世界各国电影发行量 图表...')
        # 导入TOP500电影数据
        csv_path = os.path.abspath(os.path.join(os.path.dirname("__file__"), os.path.pardir, "moviespider", "movie_info_top500.csv"))
        rows = pd.read_csv(csv_path, encoding='utf-8', dtype=str)
        # 分析并统计数据
        col_country = rows['国别'].to_frame()
        res = col_country.groupby('国别')['国别'].count().sort_values(ascending=False)
        raw_data = [i for i in res.items()]

        # 导入映射数据,英文名 -> 中文名
        country_name = pd.read_json('countries_zh_to_en.json', orient='index')
        stand_data = [i for i in country_name[0].items()]

        # 数据转换
        res_code = []
        for raw_country in raw_data:
            for stand_country in stand_data:
                if stand_country[1] in raw_country[0]:
                    res_code.append(stand_country[0])
        code = pd.DataFrame(res_code).groupby(0)[0].count().sort_values(ascending=False)
        data = []
        for k, v in code.items():
            data.append([k, v])

        # 制作图表
        c = Map()
        c.add("电影发行量", data, "world")
        c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        c.set_global_opts(title_opts=opts.TitleOpts(title="电影TOP500榜单中 - 世界各国电影发行量"),
                          visualmap_opts=opts.VisualMapOpts(max_=55))
        htmlPath = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "analyse_data", "世界各国电影发行量.html"))
        pngPath = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "analyse_data", "世界各国电影发行量.png"))
        # 生成html
        c.render(htmlPath)
        # 生成png
        # make_snapshot(snapshot, c.render(), pngPath)
        # print(get_current_time() + '|-------> 已生成 世界各国电影发行量 图表...')
        return c
Exemplo n.º 15
0
def nowconfirm_map(data_json,virus_nowconfirm_dict):
    map = Map(init_opts=opts.InitOpts(width="1900px", height="900px"))
    map.set_global_opts(
    title_opts=opts.TitleOpts(title="实时疫情地图 %s\n\n累计确诊 %d\n现有确诊 %d\n现有疑似 %d\n输入病例 %d\n累计治愈 %d\n累计死亡 %d" \
                            %(data_json['lastUpdateTime'],data_json['chinaTotal']['confirm'],data_json['chinaTotal']['nowConfirm'], \
                                data_json['chinaTotal']['suspect'],data_json['chinaTotal']['importedCase'], \
                                data_json['chinaTotal']['heal'],data_json['chinaTotal']['dead'])),
    visualmap_opts=opts.VisualMapOpts(max_=3600, is_piecewise=True,
            pieces=[
            {"max": 1999999, "min": 1000, "label": "10000人及以上", "color": "#8A0808"},
            {"max": 999, "min": 200, "label": "200-999人", "color": "#B40404"},
            {"max": 199, "min": 50, "label": "50-199人", "color": "#DF0101"},
            {"max": 49, "min": 30, "label": "30-49人", "color": "#F78181"},
            {"max": 29, "min": 10, "label": "10-29人", "color": "#F5A9A9"},
            {"max": 9, "min": 0, "label": "1-9人", "color": "#FFFFCC"},
            ], ) #最大数据范围,分段
    )
    virus_nowconfirm = list(virus_nowconfirm_dict.items())
    # {names[i]:v[i] for i in range(len(names))}
    map.add("现有确诊", data_pair=virus_nowconfirm, maptype="china", is_roam=True)
    map.render('html\全国实时现有确诊疫情地图.html')
Exemplo n.º 16
0
 def china(self):
     dirs = self.dirs
     rname = self.rname
     data = self.data
     max_l = self.max_l
     rich = {"{b}": {"color": "red"}}
     os.chdir(dirs)
     itemstyle_opts = {
         "normal": {
             "areaColor": "#323c48",
             "borderColor": "#404a59"
         },
         "emphasis": {
             "label": {
                 "show": Timeline
             },
             "areaColor": "rgba(255,255,255, 0.5)"
         }
     }
     map = Map(init_opts=opts.InitOpts(width="900px", height="800px"))
     map.add("",
             data,
             maptype='china',
             is_map_symbol_show=False,
             label_opts=opts.LabelOpts(is_show=True,
                                       formatter="{b}\n{c}",
                                       rich=rich,
                                       font_size=10))
     #map.Item(name,value)
     map.set_global_opts(
         title_opts=opts.TitleOpts(title="",
                                   subtitle="",
                                   pos_right="center",
                                   pos_top="5%"),
         visualmap_opts=opts.VisualMapOpts(max_=max_l,
                                           range_color=["white", "skyblue"],
                                           is_piecewise=False),
     )
     map.render(rname + ".html")
Exemplo n.º 17
0
def get_picture1():
    df = pd.read_csv(UPLOAD_FOLDER + '地区生产总值.csv', encoding='gbk')

    locate = list(df.地区)
    for i in range(0, len(locate)):
        locate[i] = locate[i].replace('市', '')
        locate[i] = locate[i].replace('省', '')
        locate[i] = locate[i].replace('维吾尔自治区', '')
        locate[i] = locate[i].replace('壮族自治区', '')
        locate[i] = locate[i].replace('回族自治区', '')
        locate[i] = locate[i].replace('自治区', '')
    print(locate)
    地区生产总值 = list(df.地区生产总值)
    list1 = [[locate[i], 地区生产总值[i]] for i in range(len(locate))]
    map_1 = Map()
    map_1.set_global_opts(
        title_opts=opts.TitleOpts(title="2018年中国各地区生产总值"),
        visualmap_opts=opts.VisualMapOpts(max_=100000, min_=1000)  # 最大数据范围
    )
    map_1.add("地区生产总值", list1, maptype="china")
    fig = map_1.render('./temp/example.html')
    return fig
Exemplo n.º 18
0
def draw_virus_map(virus_data, virus_title):
    """
    绘制疫情地图
    :param virus_title:
    :param virus_data:
    :return:
    """
    virus_map = Map()
    virus_data_list = []
    """
     A = [1,2,3]
     B = [4,5,6]
     zip(A, B)
     (1,4),(2,5),(3,6)
    """
    virus_zip = zip(virus_data.keys(), virus_data.values())
    for z in virus_zip:
        print(z)
        virus_data_list.append(z)

    virus_map.add(virus_title, virus_data_list, "china")
    virus_map.set_global_opts(title_opts=opts.TitleOpts("中国疫情地图"),
                              visualmap_opts=opts.VisualMapOpts(split_number=6,is_piecewise=True,
                                                                pieces=[{"min": 1, "max": 9, "label": "1-9人",
                                                                         "color": "#ffefd7"},
                                                                        {"min": 10, "max": 99, "label": "10-99人",
                                                                         "color": "#ffd2a0"},
                                                                        {"min": 100, "max": 499, "label": "100-499人",
                                                                         "color": "#fe8664"},
                                                                        {"min": 500, "max": 999, "label": "500-999人",
                                                                         "color": "#e64b47"},
                                                                        {"min": 1000, "max": 9999,
                                                                         "label": "1000-9999人", "color": "#c91014"},
                                                                        {"min": 10000, "label": "10000人及以上",
                                                                         "color": "#9c0a0d"}]),
                              tooltip_opts=opts.TooltipOpts(formatter="{b}:{c}"))
    virus_map.render(path="疫情地图.html")
Exemplo n.º 19
0
def createProvincePie(province, provinceMatchConfirm):
    provinceCitys = list(provinceMatchConfirm.keys())
    #城市名称标准化
    provinceCitys = [i + '市' if i != "境外输入" else i for i in provinceCitys]
    citysConfirm = list(provinceMatchConfirm.values())
    # provinceCitys =['济南市', '青岛市', '泰安市', '烟台市', '淄博市', '枣庄市', '潍坊市', '济宁市', '威海市','日照市','临沂市','德州市','聊城市','滨州市','菏泽市','境外输入']
    #citysConfirms=['280','63','35','47','30','24','44','260','38','16','49','37','38','15','11','22']
    list1 = [[provinceCitys[i], citysConfirm[i]]
             for i in range(len(provinceCitys))]  #首先创建数据
    #map_1
    map_1 = Map(init_opts=opts.InitOpts(
        width="400px", height="460px"))  #创建地图,其中括号内可以调整大小,也可以修改主题颜色。
    map_1.add("山东疫情", list1, maptype=province)  #添加山东地图
    map_1.set_global_opts(  #设置全局配置项
        #title_opts=opts.TitleOpts(title="山东疫情"), 添加标题
        visualmap_opts=opts.VisualMapOpts(max_=300,
                                          is_piecewise=True),  #最大数据范围 并且使用分段
        legend_opts=opts.LegendOpts(is_show=False),  #是否显示图例
    )
    #map_2
    map_2 = (
        Pie(init_opts=opts.InitOpts(width="600px", height="500px"))  #创建一个饼图
        .add(
            "",  #图名
            [[provinceCitys[i], citysConfirm[i]]
             for i in range(len(provinceCitys))],  #添加数据
            radius=["40%", "75%"],  # 调整半径
        ).set_global_opts(
            legend_opts=opts.LegendOpts(
                orient="vertical",
                pos_top="10%",
                pos_left="88%"  #图例设置
            ), ).set_series_opts(
                label_opts=opts.LabelOpts(formatter="{b}: {c}"))  #设置标签
    )
    map_1.render('blog/static/map1.html')  # 地图
    map_2.render('blog/static/map2.html')  #饼图  保存到本地
Exemplo n.º 20
0
        name_map=name_map,
        )
#设置全局配置项
map.set_global_opts(visualmap_opts=options.VisualMapOpts(max_=1100000,
                                                         is_piecewise=True,
                                                         pieces=[
                                                             {
                                                                 "min": 500000
                                                             },
                                                             {
                                                                 "min": 200000,
                                                                 "max": 499999
                                                             },
                                                             {
                                                                 "min": 100000,
                                                                 "max": 199999
                                                             },
                                                             {
                                                                 "min": 50000,
                                                                 "max": 99999
                                                             },
                                                             {
                                                                 "min": 10000,
                                                                 "max": 49999
                                                             },
                                                             {
                                                                 "max": 9999
                                                             },
                                                         ]))
#设置系列配置项
map.set_series_opts(label_opts=options.LabelOpts(is_show=False))  #不显示国家名
map.render('map.html')  #命名并保存
Exemplo n.º 21
0
from pyecharts.charts import Map, Geo
from pyecharts import options as opts
#将数据处理成列表
locate = [
    '北京', '天津', '河北', '山西', '内蒙古', '辽宁', '吉林', '黑龙江', '上海', '江苏', '浙江', '安徽',
    '福建', '江西', '山东', '河南', '湖北', '湖南', '广东', '广西', '海南', '重庆', '四川', '贵州',
    '云南', '陕西', '甘肃', '青海', '宁夏', '新疆', '西藏'
]
app_price = [
    10.84, 8.65, 18.06, 8.90, 5.04, 29.20, 8.98, 17.80, 27.81, 24.24, 12.72,
    11.10, 6.30, 7.00, 22.45, 16.92, 11.00, 14.99, 18.85, 5.85, 1.40, 7.32,
    14.61, 4.62, 6.05, 8.07, 6.73, 15.54, 13.00, 39.07, 25.61, 21.3
]
list1 = [[locate[i], app_price[i]] for i in range(len(locate))]
map_1 = Map()
map_1.set_global_opts(
    title_opts=opts.TitleOpts(title="2019年全国各省苹果价格表"),
    visualmap_opts=opts.VisualMapOpts(max_=50)  #最大数据范围
)
map_1.add("2019年全国各省苹果价格", list1, maptype="china")
map_1.render('map.html')
Exemplo n.º 22
0
        {
            'min': 1000,
            'max': 5000,
            'label': '1000-5000',
            'color': '#e57373'
        },
        {
            'min': 1000,
            'label': '5000+',
            'color': '#c62828'
        },
    ]

    # noinspection PyTypeChecker
    map.add('', zip(provices, valuse))

    map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

    map.set_global_opts(
        visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
                                          pieces=pieces,
                                          pos_left='100px'),
        tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{b}<br/>{c}"),
    )

    filepath = 'Maps/' + time + '.html'
    map.render(path=filepath)
    tl.add(map, "{}".format(time))

tl.render("ChinaChart/ChinaMap.html")
Exemplo n.º 23
0
Arquivo: 10.py Projeto: m14bz/test3
        "U.S. Virgin Is.": "美属维尔京群岛",
        "Samoa": "萨摩亚"
    }

    #确诊人数
    confirmedCount=jsonpath.jsonpath(python_list,"$..confirmedCount'")
    print(confirmedCount)

#组成字典
data_list = list(zip(countryname,confirmedCount))
print(data_list)

#中英文映射的字典


# 4 数据可视化
map = Map().add(series_name="世界疫情分布",
                data_pair=data_list,
                maptype="world",
                name_map=namemap,
                is_map_symbol_show=False
                    )


map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))    #不显示国家名称

map.set_global_opts(title_opts=opts.TitleOpts(title="国外疫情") ,  #设置标题
                    visualmap_opts=opts.VisualMapOpts(max_=30000000,is_piecewise=True))
map.render('世界疫情分布.html')

        'color': '#f27777'
    },
    {
        'max': 9,
        'min': 1,
        'color': '#f7adad'
    },
    {
        'max': 0,
        'color': '#f7e4e4'
    },
]
labels = [data[0] for data in china_data]
counts = [data[1] for data in china_data]

m = Map()
m.add("累计确诊", [list(z) for z in zip(labels, counts)], 'china')

#系列配置项,可配置图元样式、文字样式、标签样式、点线样式等
m.set_series_opts(label_opts=opts.LabelOpts(font_size=12), is_show=False)
#全局配置项,可配置标题、动画、坐标轴、图例等
m.set_global_opts(
    title_opts=opts.TitleOpts(title='全国实时确诊数据', subtitle='数据来源:丁香园'),
    legend_opts=opts.LegendOpts(is_show=False),
    visualmap_opts=opts.VisualMapOpts(
        pieces=pieces,
        is_piecewise=True,  #是否为分段型
        is_show=True))  #是否显示视觉映射配置
#render()会生成本地 HTML 文件,默认会在当前目录生成 render.html 文件,也可以传入路径参数,如 m.render("mycharts.html")
m.render(path='全国实时确诊数据MAP.html')
Exemplo n.º 25
0
        json_array_province = province['cities']
        hubei_data = [(format_city_name(city['cityName'], defined_cities), city['confirmedCount']) for city in
                      json_array_province]
        hubei_data = sorted(hubei_data, key=lambda x: x[1], reverse=True)

        print(hubei_data)

labels = [data[0] for data in hubei_data]
counts = [data[1] for data in hubei_data]
pieces = [
    {'min': 10000, 'color': '#540d0d'},
    {'max': 9999, 'min': 1000, 'color': '#9c1414'},
    {'max': 999, 'min': 500, 'color': '#d92727'},
    {'max': 499, 'min': 100, 'color': '#ed3232'},
    {'max': 99, 'min': 10, 'color': '#f27777'},
    {'max': 9, 'min': 1, 'color': '#f7adad'},
    {'max': 0, 'color': '#f7e4e4'},
]

m = Map()
m.add("累计确诊", [list(z) for z in zip(labels, counts)], '湖北')
m.set_series_opts(label_opts=opts.LabelOpts(font_size=12),
                  is_show=False)
m.set_global_opts(title_opts=opts.TitleOpts(title='湖北省实时确诊数据',
                                            subtitle='数据来源:丁香园'),
                  legend_opts=opts.LegendOpts(is_show=False),
                  visualmap_opts=opts.VisualMapOpts(pieces=pieces,
                                                    is_piecewise=True,
                                                    is_show=True))
m.render(path='/home/aistudio/data/湖北省实时确诊数据.html')
Exemplo n.º 26
0
m.set_global_opts(title_opts=opts.TitleOpts(title="各国现有确诊人数地图"),
                  visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
                                                    pieces=[{
                                                        "min": 5000,
                                                        "label": '>5000',
                                                        "color": "#893448"
                                                    }, {
                                                        "min": 1000,
                                                        "max": 4999,
                                                        "label": '1000-4999',
                                                        "color": "#ff585e"
                                                    }, {
                                                        "min": 500,
                                                        "max": 999,
                                                        "label": '500-1000',
                                                        "color": "#fb8146"
                                                    }, {
                                                        "min": 101,
                                                        "max": 499,
                                                        "label": '101-499',
                                                        "color": "#ffA500"
                                                    }, {
                                                        "min": 10,
                                                        "max": 100,
                                                        "label": '10-100',
                                                        "color": "#ffb248"
                                                    }, {
                                                        "min": 0,
                                                        "max": 9,
                                                        "label": '0-9',
                                                        "color": "#fff2d1"
                                                    }]))
Exemplo n.º 27
0
map_chart.set_global_opts(
    title_opts=opts.TitleOpts(title=f"全国疫情地图( {alldata['lastUpdateTime']} )"),
    visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
                                      pieces=[{
                                          "min": 1,
                                          "max": 9,
                                          "label": "1-9人",
                                          "color": "#FFE6BE"
                                      }, {
                                          "min": 10,
                                          "max": 99,
                                          "label": "10-99人",
                                          "color": "#FFB769"
                                      }, {
                                          "min": 100,
                                          "max": 499,
                                          "label": "100-499人",
                                          "color": "#FF8F66"
                                      }, {
                                          "min": 500,
                                          "max": 999,
                                          "label": "500-999人",
                                          "color": "#ED514E"
                                      }, {
                                          "min": 1000,
                                          "max": 9999,
                                          "label": "1000-9999人",
                                          "color": "#CA0D11"
                                      }, {
                                          "min": 10000,
                                          "max": 100000,
                                          "label": "10000人以上",
                                          "color": "#A52A2A"
                                      }]))
Exemplo n.º 28
0
colors = sns.color_palette("Blues", 10).as_hex()

time_map = Timeline()
attr = populations.columns.tolist()
for time in populations.index:
    values = populations.loc[time].tolist()
    popu_map = Map()
    popu_map.add("", [list(z) for z in zip(attr, values)],
                 maptype="china",
                 is_map_symbol_show=False)
    popu_map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    popu_map.set_global_opts(title_opts=opts.TitleOpts(
        title="China population by province from 2000 to 2018",
        subtitle="Units: 10K"),
                             visualmap_opts=opts.VisualMapOpts(
                                 max_=12000,
                                 is_piecewise=True,
                                 split_number=12,
                                 range_color=colors),
                             toolbox_opts=opts.ToolboxOpts())
    time_map.add(popu_map, "{}".format(time))
time_map.render("plots/population-map-over-time.html")

#动态展示各省市人口变化
sorted_pops = []
for year in range(2000, 2019):
    populations.sort_values(year, axis=1, inplace=True)
    sorted_pops.append(
        [year, populations.loc[year].tolist(),
         populations.columns.tolist()])
map_CFR.set_global_opts(
    visualmap_opts=opts.VisualMapOpts(
        max_=max_visual,
        is_piecewise=True,
        pieces=[{
            "min":
            data_map.loc[:, "case_fatality_ratio"].describe()[3],
            "max":
            (data_map.loc[:, "case_fatality_ratio"].describe()[4] - 1e-10),
            "label":
            "Below first quartile"
        }, {
            "min":
            data_map.loc[:, "case_fatality_ratio"].describe()[4],
            "max":
            (data_map.loc[:, "case_fatality_ratio"].describe()[5] - 1e-10),
            "label":
            "Below median"
        }, {
            "min":
            data_map.loc[:, "case_fatality_ratio"].describe()[5],
            "max":
            (data_map.loc[:, "case_fatality_ratio"].describe()[6] - 1e-10),
            "label":
            "Above median"
        }, {
            "min": data_map.loc[:, "case_fatality_ratio"].describe()[6],
            "max": data_map.loc[:, "case_fatality_ratio"].describe()[7],
            "label": "Above third quartile"
        }]),
    title_opts=opts.TitleOpts(
        title=
        "Worldwide Covid-19 Case Fatality Rate Corrected for Positive Rate",
        subtitle=
        "Most recently available data used from doi: 10.1038/s41597-020-00688-8",
        pos_left="center",
        padding=0,
        item_gap=2,
        title_textstyle_opts=opts.TextStyleOpts(color="firebrick",
                                                font_weight="bold",
                                                font_family="Times New Roman",
                                                font_size=30),
        subtitle_textstyle_opts=opts.TextStyleOpts(
            color="darkblue",
            font_weight="bold",
            font_family="Times New Roman",
            font_size=13)),
    legend_opts=opts.LegendOpts(is_show=False))
Exemplo n.º 30
0
def generate_heat_map(date, country='世界', province=''):
    # 累计病例热力图
    if country == '世界':
        countries = ['Albania', 'Algeria', 'Afghanistan', 'Argentina', 'Akrotiri and Dhekelia', 'United Arab Emirates',
                   'Aruba', 'Oman', 'Azerbaijan', 'Egypt', 'Ethiopia', 'Ireland', 'Estonia', 'Andorra', 'Angola',
                   'Anguilla', 'Antigua and Barbuda', 'Austria', 'Aland', 'Australia', 'Barbados', 'Papua New Guinea',
                   'Bahamas', 'Pakistan', 'Paraguay', 'Palestine', 'Bahrain', 'Panama', 'Brazil', 'Belarus', 'Bermuda',
                   'Bulgaria', 'Northern Mariana Islands', 'Northern Cyprus', 'Benin', 'Belgium', 'Iceland', 'Poland',
                   'Bosnia and Herzegovina', 'Bolivia', 'Belize', 'Botswana', 'Bonaire, Sint Eustatius and Saba',
                   'Bhutan', 'Burkina Faso', 'Bouvet Island', 'North Korea', 'Equatorial Guinea', 'Denmark', 'Germany',
                   'Timor-Leste', 'Togo', 'Dominica', 'Dominica', 'Russia', 'Ecuador', 'Eritrea', 'France',
                   'Faroe Islands', 'French Polynesia', 'French Guiana', 'French Southern Territories', 'Vatican City',
                   'Philippines', 'Fiji', 'Finland', 'Cape Verde', 'Falkland Islands', 'Gambia', 'Republic of Congo',
                   'Democratic Republic of the Congo', 'Colombia', 'Costa Rica', 'Guernsey', 'Grenada', 'Greenland',
                   'Georgia', 'Cuba', 'Guadeloupe', 'Guam', 'Guyana', 'Kazakhstan', 'Haiti', 'South Korea',
                   'Netherlands', 'Heard Island and McDonald Islands', 'Montenegro', 'Ruby Princess', 'Honduras',
                   'Kiribati', 'Djibouti', 'Kyrgyzstan', 'Guinea', 'Guinea-Bissau', 'Canada', 'Ghana', 'Gabon',
                   'Burundi', 'Cambodia', 'Czech Republic', 'Zimbabwe', 'Cameroon', 'Qatar', 'Cayman Islands',
                   'Cocos Islands', 'Comoros', 'Kosovo', "Côte d'Ivoire", 'Kuwait', 'Clipperton Island', 'Croatia',
                   'Kenya', 'Cook Islands', 'Curaçao', 'Latvia', 'Lesotho', 'Laos', 'Lebanon', 'Caspian Sea',
                   'Lithuania', 'Liberia', 'Libya', 'Liechtenstein', 'Reunion', 'Luxembourg', 'Rwanda', 'Romania',
                   'Madagascar', 'Isle of Man', 'Maldives', 'Malta', 'Malawi', 'Malaysia', 'Mali', 'Macedonia',
                   'Marshall Islands', 'Martinique', 'Mayotte', 'Mauritius', 'Mauritania', 'United States',
                   'Virgin Islands, U.S.', 'United States Minor Outlying Islands', 'American Samoa', 'Mongolia',
                   'Montserrat', 'Bangladesh', 'Peru', 'Micronesia', 'Myanmar', 'Moldova', 'Morocco', 'Monaco',
                   'Mozambique', 'Mexico', 'Namibia', 'South Africa', 'Antarctica',
                   'South Georgia and the South Sandwich Islands', 'Spratly Islands', 'South Sudan', 'Nauru', 'Nepal',
                   'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norway', 'Norfolk Island', 'Palestina', 'Palau',
                   'Pitcairn Islands', 'Portugal', 'Japan', 'Sweden', 'Switzerland', 'El Salvador', 'Samoa', 'Serbia',
                   'Sierra Leone', 'Senegal', 'Cyprus', 'Seychelles', 'Saudi Arabia', 'Saint-Barthélemy',
                   'Christmas Island', 'São Tomé and Príncipe', 'Saint Helena', 'Saint Kitts and Nevis', 'Saint Lucia',
                   'Saint-Martin', 'San Marino', 'Saint Pierre and Miquelon', 'Saint Vincent and the Grenadines',
                   'Sri Lanka', 'Slovakia', 'Slovenia', 'Svalbard and Jan Mayen', 'Swaziland', 'Sudan', 'Suriname',
                   'Solomon Islands', 'Somalia', 'Tajikistan', 'Thailand', 'Tanzania', 'Tonga',
                   'Turks and Caicos Islands', 'Trinidad and Tobago', 'Tunisia', 'Tuvalu', 'Turkey', 'Turkmenistan',
                   'Tokelau', 'Wallis and Futuna', 'Vanuatu', 'Guatemala', 'Venezuela', 'Brunei', 'Uganda', 'Ukraine',
                   'Uruguay', 'Uzbekistan', 'Spain', 'Western Sahara', 'Paracel Islands', 'Greece', 'Sint Maarten',
                   'Singapore', 'New Caledonia', 'New Zealand', 'Hungary', 'Syria', 'Jamaica', 'Armenia', 'Yemen',
                   'Iraq', 'Iran', 'Israel', 'Italy', 'India', 'Indonesia', 'United Kingdom', 'British Virgin Islands',
                   'British Indian Ocean Territory', 'Jordan', 'Vietnam', 'Zambia', 'Jersey', 'Chad', 'Gibraltar',
                   'Chile', 'Central African Republic', 'China', 'Diamond Princess']

        # case_num = [fetch_country_data(date, date, country) for country in countries]
        case_num = [650, 2546, 558, 1728, 0, 4804, 89, 1117, 1620, 2002, 97, 17110, 750, 545, 13, 0, 19, 13991, 0, 6163,
                    57, 8, 37, 8023, 155, 263, 2065, 4501, 61685, 6406, 0, 444, 0, 0, 62, 13642, 1773, 5698, 1106, 258,
                    16, 12, 0, 5, 569, 0, 0, 13, 8415, 147171, 21, 87, 2584, 14, 34306, 3433, 37, 56148, 157, 56, 122,
                    0, 2, 1924, 14, 4000, 56, 0, 9, 33, 136, 2569, 480, 0, 13, 11, 309, 1140, 0, 0, 35, 1901, 17, 9610,
                    322, 0, 274, 0, 195, 0, 834, 675, 698, 25, 31262, 378, 110, 7, 120, 4448, 9, 1465, 2753, 0, 0, 0, 0,
                    769, 2729, 0, 1764, 239, 0, 0, 464, 0, 13, 234, 0, 828, 83, 24, 55, 0, 3550, 140, 7051, 101, 0, 29,
                    433, 14, 5025, 298, 1136, 0, 0, 0, 320, 6, 238081, 0, 0, 0, 13, 2, 2650, 20246, 0, 72, 1925, 2545,
                    82, 34, 21824, 11, 3983, 0, 0, 0, 2, 0, 31, 7, 617, 745, 0, 32, 0, 0, 0, 0, 2549, 5906, 4971, 26400,
                    293, 0, 2732, 67, 650, 401, 10, 11457, 0, 0, 4, 0, 14, 17, 0, 126, 0, 9, 321, 941, 256, 0, 14, 119,
                    9, 0, 110, 0, 2794, 183, 0, 5, 104, 660, 0, 89480, 0, 0, 0, 0, 104, 190, 134, 55, 3060, 513, 1881,
                    176439, 5, 0, 1374, 0, 2296, 17, 1371, 933, 29, 78, 1325, 1, 1702, 86143, 11384, 103031, 19358,
                    2698, 1002, 0, 0, 387, 241, 117, 0, 53, 142, 12667, 10, 79527, 645]

        world = Map()
        world.add('{}疫情地图'.format(country), [list(z) for z in zip(countries, case_num)], 'world')
        world.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        world.set_global_opts(title_opts=opts.TitleOpts(title='截至5月26日各国的累计治愈人数'),
                              visualmap_opts=opts.VisualMapOpts(max_=cal_upper_bound(max(case_num)),
                                                                is_piecewise=True,
                                                                range_color=('#ffffff', '#ff3838')
                                                                )
                              )
        world.render(path='2.html')

    elif province == '全国':
        provinces = ['新疆', '西藏', '青海', '甘肃', '四川', '云南', '宁夏', '陕西', '重庆', '贵州', '广西', '内蒙古',
                         '山西', '河南', '湖北', '湖南', '广东', '澳门', '香港', '海南', '江西', '安徽', '河北', '北京',
                         '天津', '安徽', '江苏', '浙江', '上海', '福建', '山东', '南海诸岛', '台湾', '辽宁', '吉林',
                         '黑龙江']

        case_num = [fetch_province_data(date, date, province) for province in provinces]

        world = Map()
        world.add('{}疫情地图'.format(country), [list(z) for z in zip(provinces, case_num)], country)
        world.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        world.set_global_opts(title_opts=opts.TitleOpts(title='截至5月26日各国的累计治愈人数'),
                              visualmap_opts=opts.VisualMapOpts(max_=cal_upper_bound(max(case_num)),
                                                                is_piecewise=True,
                                                                range_color=('#ffffff', '#ff3838')
                                                                )
                              )
        world.render(path='2.html')

    else:
        cities = ['北京']

        case_num = [fetch_city_data(data, data, city) for city in cities]

        world = Map()
        world.add('{}疫情地图'.format(province), [list(z) for z in zip(cities, case_num)], 'province')
        world.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        world.set_global_opts(title_opts=opts.TitleOpts(title='截至5月26日各国的累计治愈人数'),
                              visualmap_opts=opts.VisualMapOpts(max_=cal_upper_bound(max(case_num)),
                                                                is_piecewise=True,
                                                                range_color=('#ffffff', '#ff3838')
                                                                )
                              )
        world.render(path='2.html')