Beispiel #1
0
def geo_line() -> Bar:
    db = getattr(g, "_db", None)
    col = db.trafficmodels
    users = col.distinct("user")
    list_place = []
    for user in users:
        place = col.find_one({"user": user}, {"place": 1})["place"]
        places = get_all_IP(user)

        for p in places:
            list_place.append([place, p])
    c = (Geo().add_schema(maptype="world").add_coordinate_json(
        json_file="world_country.json").add(
            "交互图",
            list_place,
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.DIAMOND,
                                        symbol_size=6,
                                        color="blue"),
            linestyle_opts=opts.LineStyleOpts(
                curve=0.2,
                opacity=0.2,
            )).set_series_opts(label_opts=opts.LabelOpts(
                is_show=False)).set_global_opts(
                    title_opts=opts.TitleOpts(title="总交互图"),
                    tooltip_opts=opts.TooltipOpts(is_show=True)))
    return c
Beispiel #2
0
def geo_charts(content):
    """绘制世界地图"""
    zip_data = content[0]
    start_city = content[1]
    geo = (Geo().add_schema(
        maptype="china",
        itemstyle_opts=opts.ItemStyleOpts(color="#323c48",
                                          border_color="#00000"),
    ).add(
        "",
        data_pair=zip_data,
        type_=ChartType.EFFECT_SCATTER,
        color="white",
    ).add(
        "geo",
        data_pair=start_city,
        type_=GeoType.LINES,
        effect_opts=opts.EffectOpts(symbol=SymbolType.RECT,
                                    symbol_size=6,
                                    color="yellow",
                                    is_show=True),
        linestyle_opts=opts.LineStyleOpts(curve=0.2),
    ).set_series_opts(label_opts=opts.LabelOpts(
        is_show=False)).set_global_opts(title_opts=opts.TitleOpts(
            title="Python开发工程师可视化界面")))
    return geo
Beispiel #3
0
def geo_lines() -> Geo:
    c = (
        Geo(
                init_opts=opts.InitOpts(width="1000px",height="700px",theme=ThemeType.PURPLE_PASSION)
        )
        .add_schema(maptype="china")
        .add(
            "航班数量",
           df2,
            type_=ChartType.EFFECT_SCATTER,
            #color="#ffa022"
        )
        .add(
            "航线",
            df1,
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(
                symbol=symbol_list[0], symbol_size=15, period=6, trail_length=0, is_show=True
            ),
            linestyle_opts=opts.LineStyleOpts(curve=0.2,  width=1, opacity=0.5),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="国内航线", #pos_left="center",
                        title_textstyle_opts=opts.TextStyleOpts(font_size=30, font_weight="bold"),
                        #subtitle_textstyle_opts=opts.TextStyleOpts(color='black',font_size=15)
                                                   ))
        )
Beispiel #4
0
 def geoLineCity(self, data) -> Geo:
     # 指定城市航班连接城市图
     count = len(data[0])
     city_Geoline = (
         Geo(init_opts=opts.InitOpts(
             width='1000px', height='500px')).add_schema(
                 maptype="china", zoom=1.1).add_coordinate_json(
                     self.geo_file).add("",
                                        data[1],
                                        symbol_size=6,
                                        color='#725e82')  # 标记点大小与颜色
         .add(
             "",
             data[0],
             type_=ChartType.LINES,
             linestyle_opts=opts.LineStyleOpts(curve=0.1,
                                               width=1,
                                               color='#1685a9'),  # 连线的宽度与颜色
             effect_opts=opts.EffectOpts(is_show=False))  # 关闭涟漪效果
         .set_series_opts(label_opts=opts.LabelOpts(
             is_show=False)).set_global_opts(title_opts=opts.TitleOpts(
                 title="{}民航班机航线图".format(data[0][0][0]),
                 subtitle='{},{}共有直飞全国{}个城市的航班'.format(
                     self.today_ymd, data[0][0][0], count))))
     return city_Geoline
Beispiel #5
0
def geo_lines() -> Geo:
    c = (
        Geo()
        .add_schema(maptype="china")
        .add(
            "",
            [("北京", 1), ("重庆", 2), ("长沙", 3), ("长春", 4), ("成都", 5), ("大连", 6), ("广州", 7), ("贵阳", 8),
            ("合肥", 9), ("杭州", 10), ("哈尔滨", 11), ("海口", 12), ("济南", 13), ("昆明", 14), ("柳州", 15), ("绵阳", 16),
            ("潞西市", 17), ("南宁", 18), ("南京", 19), ("沈阳", 20), ("三亚", 21), ("上海", 22), ("天津", 23), ("徐州", 24),
            ("义乌", 25), ("郑州", 26), ("张家界", 27)],
            type_=ChartType.EFFECT_SCATTER,
            color="#ffa022"
        )
        .add(
            "",
            [("揭阳", "北京"), ("揭阳", "重庆"), ("揭阳", "长沙"), ("揭阳", "长春"), ("揭阳", "成都"),
            ("揭阳", "大连"), ("揭阳", "广州"), ("揭阳", "贵阳"), ("揭阳", "合肥"), ("揭阳", "杭州"),
            ("揭阳", "哈尔滨"), ("揭阳", "海口"), ("揭阳", "济南"), ("揭阳", "昆明"), ("揭阳", "柳州"),
            ("揭阳", "绵阳"), ("揭阳", "潞西市"), ("揭阳", "南宁"), ("揭阳", "南京"), ("揭阳", "沈阳"),("揭阳", "三亚"),
            ("揭阳", "上海"), ("揭阳", "天津"), ("揭阳", "徐州"),("揭阳", "义乌"),("揭阳", "郑州"), ("揭阳", "张家界")],
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(
                symbol=symbol_list[0], symbol_size=15, color='#a6c84c', period=6, trail_length=0, is_show=True
                # 特效图形的标记。有 RECT', 'DIAMOND', 'ARROW' 可选
            ),
            linestyle_opts=opts.LineStyleOpts(curve=0.2, color='#46bee9', width=1, opacity=0.5),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="揭阳出发国内航线", subtitle="数能工作室制作", pos_left="center",
                        title_textstyle_opts=opts.TextStyleOpts(color='black',font_size=20, font_weight="bold"),
                        subtitle_textstyle_opts=opts.TextStyleOpts(color='black',font_size=15),item_gap=15))
        )
    return c
Beispiel #6
0
def get_eventbmap(pos) -> BMap:
    #[(lo,la),(lo,la)]这种格式即可
    BAIDU_AK = "HOTBRAfU1jGcQKHBX15ucKsfZO722eyN"
    center = (117.20, 39.12)
    c = BMap()
    c.add_schema(
        baidu_ak=BAIDU_AK,
        center=[117.20, 39.12],
        zoom=10,
        is_roam=False,
    )
    sequence = []
    for i in range(len(pos)):
        c.add_coordinate(str(i), pos[i][0], pos[i][1])  #[(posindex,lo,la)]
        sequence.append((str(i), 0.1))  #这里名字和pos要对应
    c.add(
        "投诉坐标",  #系列名称
        sequence,
        type_="scatter",  #"heatmap" 可以切换显示的类型热力图或散点图
        label_opts=opts.LabelOpts(formatter="{b}"),
        symbol_size=5)
    c.set_series_opts(effect_opts=opts.EffectOpts(is_show=True),
                      label_opts=opts.LabelOpts(is_show=False))
    c.add_control_panel(
        scale_control_opts=opts.BMapScaleControlOpts(),
        navigation_control_opts=opts.BMapNavigationControlOpts(),
        maptype_control_opts=opts.BMapTypeControlOpts())
    #c.set_global_opts(visualmap_opts=opts.VisualMapOpts())
    return c
def generate_drug_map(date, type='疫苗'):
    data = fetch_drug_date(date, type)
    points = []
    for country, num in data:
        poins.append('1', random.sample(random_points[country], num))
    count = [1] * len(data)
    addresses = []
    json_data = {}
    for address in test_data:
        json_data[address[0]] = [address[1], address[2]]
        addresses.append(address[0])

    json_str = json.dumps(json_data, ensure_ascii=False, indent=4)
    with open('test_data.json', 'w', encoding='utf-8') as json_file:
        json_file.write(json_str)

    geo = Geo()
    geo.add_schema(maptype='world')
    geo.add_coordinate_json(json_file='test_data.json')
    geo.add('研发中的{}类药物'.format(type), [list(z) for z in zip(addresses, data)], type_=ChartType.EFFECT_SCATTER, color='#1e90ff',
            symbol_size=10, symbol='diamond')
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False), effect_opts=opts.EffectOpts(scale=5))
    geo.set_global_opts(title_opts=opts.TitleOpts(title="Geo-EffectScatter"),
                        tooltip_opts=opts.TooltipOpts(is_show=False))
    geo.render(path='3.html')
Beispiel #8
0
    def pyechart_Geo_plot(self):
        from pyecharts.charts import Geo
        file_name = '地理图.html'
        path_plotly = self.path_dir_plotly_html + os.sep + file_name  # 文件路径,前面是文件夹后面是文件名
        #costumeTheme = self.themedict[para['theme']]
        #df= pd.read_excel(filedata, sheet_name='Sheet1')

        c = (Geo().add_schema(
            maptype="china",
            itemstyle_opts=opts.ItemStyleOpts(color="#323c48",
                                              border_color="#111"),
        ).add(
            "",
            [("广州", 55), ("北京", 66), ("杭州", 77), ("重庆", 88)],
            type_=ChartType.EFFECT_SCATTER,
            color="white",
        ).add(
            "geo",
            [("广州", "上海"), ("广州", "北京"), ("广州", "杭州"), ("广州", "重庆")],
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=6,
                                        color="blue"),
            linestyle_opts=opts.LineStyleOpts(curve=0.2),
        ))

        return path_plotly  # 返回该HTML文件路径
def geo_lines_background() -> Geo:
    c = (
        Geo()
        .add_schema(
            maptype="china",
            itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"),
        )
        .add(
            "",
            [("广州", 55), ("北京", 66), ("杭州", 77), ("重庆", 88)],
            type_=ChartType.EFFECT_SCATTER,
            color="white",
        )
        .add(
            "geo",
            [("广州", "上海"), ("广州", "北京"), ("广州", "杭州"), ("广州", "重庆")],
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(
                symbol=SymbolType.ARROW, symbol_size=6, color="blue"
            ),
            linestyle_opts=opts.LineStyleOpts(curve=0.2),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="Geo-Lines-background"))
    )
    return c
Beispiel #10
0
def polar_effectscatter() -> Polar:
    data = [(i, random.randint(1, 100)) for i in range(10)]
    c = (Polar().add(
        "",
        data,
        type_="effectScatter",
        effect_opts=opts.EffectOpts(scale=10, period=5),
        label_opts=opts.LabelOpts(is_show=False),
    ).set_global_opts(title_opts=opts.TitleOpts(title="Polar-EffectScatter")))
    return c
Beispiel #11
0
 def geo_map() -> Geo:
     output = (
         Geo(init_opts=options.InitOpts(
             width="700px",
             height="500px",
             bg_color="#FFFFFF",
             page_title="全国疫情实时数据")).add_schema(
                 maptype="china",
                 itemstyle_opts=options.ItemStyleOpts(
                     color="RGB(204,204,204)",
                     border_color="rgb(204,51,51)"),
                 is_roam="false").add("geo",
                                      data_pair=pc_list,
                                      type_=GeoType.EFFECT_SCATTER).
         set_series_opts(
             label_opts=options.LabelOpts(is_show=False),
             effect_opts=options.EffectOpts(scale=6)).set_global_opts(
                 visualmap_opts=options.VisualMapOpts(
                     is_piecewise=True,
                     pieces=[{
                         "min": 1,
                         "max": 9,
                         "label": '1到9人'
                     }, {
                         "min": 10,
                         "max": 99,
                         "label": '10到99人'
                     }, {
                         "min": 100,
                         "max": 499,
                         "label": '100到499人'
                     }, {
                         "min": 500,
                         "max": 999,
                         "label": '500到999人'
                     }, {
                         "min": 1000,
                         "max": 9999,
                         "label": '1000到9999人'
                     }, {
                         "min": 10000,
                         "label": '10000人以上'
                     }]),
                 title_opts=options.TitleOpts(
                     title="全国疫情热点地图",
                     subtitle=title_ncp_summary,
                     pos_left="center",
                     pos_top="10px",
                     title_textstyle_opts=options.TextStyleOpts(
                         color="#080808"),
                     subtitle_textstyle_opts=options.TextStyleOpts(
                         color="#080808")),
                 legend_opts=options.LegendOpts(is_show=False))  # 不显示图例
     )
     return output
Beispiel #12
0
def out_data(date_number):
    city_list = ('南宁市', '柳州市', '桂林市', '梧州市', '北海市', '防城港市', '钦州市', '贵港市',
                 '玉林市', '百色市', '贺州市', '河池市', '来宾市', '崇左市')
    city_od_list_pro = []
    city_od_values_pro = []
    for i in city_list:
        city = i
        workbook = xlrd.open_workbook(f'.\\{path}\\{city}-迁入来源地规模指数.xlsx')
        sheet = workbook.sheet_by_index(0)
        city_od_list = []
        city_od_values = []
        a = 0
        cols = sheet.col_values(1)[1:]
        cols_date = sheet.col_values(date_number + 1)[1:]
        for j in cols:
            city_od = (city, j)
            city_od_v = (j, cols_date[a])
            city_od_list.append(city_od)
            city_od_values.append(city_od_v)
            a += 1
        city_od_list_pro.append(city_od_list)
        city_od_values_pro.append(city_od_values)
    od_list = []
    os_values = []
    for i in range(14):
        for j in range(14):
            od_list.append(city_od_list_pro[i][j])
            os_values.append(city_od_values_pro[i][j])
    # print(od_list)
    # print(os_values)
    geo = Geo()
    # 地图类型,世界地图可换为world
    geo.add_schema(maptype="广西")
    # 添加数据点
    geo.add("%", os_values, type_=ChartType.EFFECT_SCATTER)
    # 添加流向,type_设置为LINES,涟漪配置为箭头,提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle',
    # 'diamond', 'pin', 'arrow', 'none'
    geo.add("迁出城市",
            od_list,
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=5,
                                        color="yellow"),
            linestyle_opts=opts.LineStyleOpts(curve=0.2),
            is_large=True)
    # 不显示标签
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 设置图标标题,visualmap_opts=opts.VisualMapOpts()为左下角的视觉映射配置项
    geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(),
                        title_opts=opts.TitleOpts(title="广西地市迁徙数据"))
    # 直接在notebook里显示图表
    geo.render_notebook()
    # 生成html文件,可传入位置参数
    geo.render(f".\\out_od\\广西-2020.10.{date_number}迁出OD图.html")
Beispiel #13
0
def plot():
    # 初始化图表信息
    geo = Geo(init_opts=opts.InitOpts(width="96vw",
                                      height="96vh",
                                      page_title="教育网拓扑图",
                                      animation_opts=opts.AnimationOpts(
                                          animation=False)))

    # 添加地图
    geo.add_schema(maptype="china")

    # 添加所有点的地理信息
    geo.add_coordinate_json("./data/data.json")

    # 画中间节点
    geo.add("Route", [(i, "Route") for i in Nodes_Route],
            color="Red",
            point_size=4,
            symbol_size=4,
            effect_opts=opts.EffectOpts(is_show=False))

    # 画目的节点
    geo.add("Dst", [(i, "Dst") for i in Nodes_Dst],
            color="SeaGreen",
            point_size=4,
            symbol_size=4,
            effect_opts=opts.EffectOpts(is_show=False))

    # 画线 展示拓扑信息
    geo.add("",
            list(Trace),
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(is_show=False, symbol_size=2),
            linestyle_opts=opts.LineStyleOpts(curve=0.1))

    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(title_opts=opts.TitleOpts(title="教育网拓扑图"))

    # 生成图表到指定文件
    geo.render("./dist/render.html")
Beispiel #14
0
def geo_lines(new_location_line, location_info) -> Geo:
    c = (Geo().add_schema(maptype="china").add_coordinate_json(
        json_file='location.json').add(
            "仓库",
            location_info,
            type_=ChartType.EFFECT_SCATTER,
            color="#ADD8E6",
        ).add(
            "线路",
            new_location_line,
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=3,
                                        color="purple",
                                        is_show=True),
            linestyle_opts=opts.LineStyleOpts(curve=0.2),
        ).set_series_opts(label_opts=opts.LabelOpts(
            is_show=True, position="middle", formatter="{b}")).set_global_opts(
                title_opts=opts.TitleOpts(title="网络")))
    # c = (
    #     Geo()
    #     .add_schema(maptype="china")
    #     .add_coordinate_json(json_file=new_location_records)
    #     .add(
    #         "",
    #         [("广州", 55), ("北京", 66), ("杭州", 77), ("重庆", 88)],
    #         type_=ChartType.EFFECT_SCATTER,
    #         color="white",
    #     )
    #     .add(
    #         "geo",
    #         [("广州", "上海"), ("广州", "北京"), ("广州", "杭州"), ("广州", "重庆"), ("重庆", "北京")],
    #         type_=ChartType.LINES,
    #         effect_opts=opts.EffectOpts(
    #             symbol=SymbolType.ARROW, symbol_size=6, color="purple"
    #         ),
    #         linestyle_opts=opts.LineStyleOpts(curve=0.2),
    #     )
    #     .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    #     .set_global_opts(title_opts=opts.TitleOpts(title="Geo-Map-Lines"))
    # )

    # 返回 html
    # return c.render_embed()

    # 返回 json
    # return c.dump_options()
    # 但是无法加载

    # c.render('geo_view.html')
    return c.dump_options_with_quotes()
Beispiel #15
0
def test_bmap_effect_trail_length(fake_writer):
    bmap = (BMap().add_schema(
        baidu_ak=FAKE_API_KEY,
        center=[-0.118092,
                51.509865]).add_coordinate("London", -0.118092, 51.509865).add(
                    "bmap",
                    [list(z) for z in zip(TEST_LOCATION, TEST_VALUE)],
                    type_=ChartType.LINES,
                    effect_opts=opts.EffectOpts(trail_length=0.5),
                    label_opts=opts.LabelOpts(formatter="{b}"),
                ))
    bmap.render("render.html")
    content = fake_writer.call_args[0][1]
    assert_in('"trailLength": 0.5', content, "trainLength parameter is error")
Beispiel #16
0
def geo_effectscatter(data, width, height) -> Geo:
    data = [list(z) for z in zip(data.index, data.values)]

    c = (
        Geo(init_opts=opts.InitOpts(width="{}px".format(width), height="{}px".format(height)))
            .add_schema(maptype="china", is_roam=False,
                        itemstyle_opts=opts.ItemStyleOpts(color='#0f1c2f', border_color="#ace3f0", border_color0='red'))
            .add("各省通过率",
                 data,
                 type_=ChartType.EFFECT_SCATTER,
                 effect_opts=opts.EffectOpts(scale=1000), color="#d0f551")
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
            .set_global_opts(legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts(pos_left='70%'))
    )
    return c
Beispiel #17
0
 def net_work_map(self, source_list, cost, destination_list, demand, source,
                  destination) -> Geo:
     """
     output the network map based on the source and destination pair.
     :param source_list: the unique source list
     :param cost: the cost of source list
     :param destination_list: the unique destination list
     :param demand: the demand of destination
     :param source: the all source point
     :param destination: the all destination point
     :return:
     """
     c = (
         Geo().add_schema(maptype="china").add(
             "", [z for z in zip(source_list, cost)],
             type_=ChartType.SCATTER,
             color='green',
             symbol_size=5,
             symbol="image://..\\icon\\warehouse_1.png").add(
                 "",
                 [z for z in zip(destination_list, demand)],
                 type_=ChartType.SCATTER,
                 color='black',
                 symbol_size=5,
                 # symbol="image://..\\icon\\customer.png"
             ).add(
                 "Network",
                 [list(z) for z in zip(source, destination)],
                 type_=ChartType.LINES,
                 symbol=[None, 'arrow'],
                 symbol_size=3,
                 effect_opts=opts.EffectOpts(
                     period=20,
                     scale=1,
                     symbol="image://..\\icon\\car.png",
                     symbol_size=15,
                     color="blue",
                     trail_length=0),
                 linestyle_opts=opts.LineStyleOpts(curve=0.1, opacity=0.3),
             ).set_series_opts(label_opts=opts.LabelOpts(
                 is_show=False)).set_global_opts(
                     title_opts=opts.TitleOpts(title="Allocation Network"),
                     visualmap_opts=opts.VisualMapOpts(is_piecewise=False,
                                                       max_=max(demand),
                                                       type_='size',
                                                       range_size=[10,
                                                                   20])))
     return c
Beispiel #18
0
    def bmap_linemap() -> BMap:
        c = (
            BMap(init_opts=opts.InitOpts(
                theme="white", width="1000px", height="600px")).add_schema(
                    baidu_ak=Baidu_AK,
                    center=[110.3131940000, 20.0274250000],
                    zoom=13)  #缩放比例12-14之间可行
            .set_global_opts(
                title_opts=opts.TitleOpts(
                    title="10/01 国庆节 机场出发"),  # 更改title====================
                visualmap_opts=opts.VisualMapOpts(),
            ))
        # 增加坐标点
        for key, value in index_lngLat.items():
            c.add_coordinate(key, value[0], value[1])

        # 增加坐标点的值
        c.add(
            "",
            index_value,
            type_=ChartType.EFFECT_SCATTER,
            symbol_size=4,
            label_opts=opts.LabelOpts(is_show=False),
            color="white",
        )

        # 增加连线图
        c.add(
            "行程起始-终止位置",
            route_pair,
            type_=ChartType.LINES,
            is_large=True,
            large_threshold=100,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=5,
                                        color="blue"),
            linestyle_opts=opts.LineStyleOpts(curve=0.1, opacity=0.7),
        )
        # c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

        c.add_control_panel(
            navigation_control_opts=opts.BMapNavigationControlOpts(
                offset_height=30),
            scale_control_opts=opts.BMapScaleControlOpts(),
        )
        return c
Beispiel #19
0
def get_baidu_map_line(new_location_line) -> BMap:
    baidu_map_key = config.get('baidu_ak')
    c = (
        BMap().add_schema(baidu_ak=baidu_map_key,
                          center=[120.13066322374, 30.240018034923]).
        add(
            "bmap",
            new_location_line,
            # [list(z) for z in zip(Faker.provinces, Faker.values())],
            # label_opts=opts.LabelOpts(formatter="{b}"),
            type_=GeoType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=6,
                                        color="purple"),
            linestyle_opts=opts.LineStyleOpts(curve=0.2),
        ).set_global_opts(title_opts=opts.TitleOpts(title="BMap-网络")))
    # return c.render_embed()
    return c.dump_options_with_quotes()
Beispiel #20
0
def set_goc(data,china_total):
    num = len(data)
    geo = (
        Geo(init_opts=opts.InitOpts(width="1200px", height="600px", bg_color="#404a59", page_title="全国疫情实时报告",
                                    renderer=RenderType.SVG, theme="white"))  # 设置绘图尺寸,背景色,页面标题,绘制类型
            .add_schema(maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="rgb(49,60,72)",
                                                                           border_color="rgb(0,0,0)"))  # 中国地图,地图区域颜色,区域边界颜色
            .add(series_name="geo", data_pair=data, type_=GeoType.EFFECT_SCATTER)  # 设置地图数据,动画方式为涟漪特效effect scatter
            .set_series_opts(  # 设置系列配置
            label_opts=opts.LabelOpts(is_show=False),  # 不显示Label
            effect_opts=opts.EffectOpts(scale=6))  # 设置涟漪特效缩放比例
            .set_global_opts(  # 设置全局系列配置
            # visualmap_opts=opts.VisualMapOpts(min_=0, max_=sum / len(data)),  # 设置视觉映像配置,最大值为平均值
            visualmap_opts=opts.VisualMapOpts(min_=0, max_=num),  # 设置视觉映像配置,最大值为平均值
            title_opts=opts.TitleOpts(title="全国疫情地图", subtitle=china_total, pos_left="center", pos_top="10px",
                                      title_textstyle_opts=opts.TextStyleOpts(color="#fff")),  # 设置标题,副标题,标题位置,文字颜色
            legend_opts=opts.LegendOpts(is_show=False),  # 不显示图例
        )
    )
    geo.render(path="./render.html")
Beispiel #21
0
 def makeMap(self, data, lines) -> Geo:
     count = len(lines)
     c = (
         Geo(init_opts=opts.InitOpts(
             width='1000px', height='500px')).add_schema(
                 maptype="china",
                 zoom=1.1).add_coordinate_json('positions.json').add(
                     "", data, symbol_size=6, color='#725e82')  # 标记点大小与颜色
         .add(
             "",
             lines,
             type_=ChartType.LINES,
             linestyle_opts=opts.LineStyleOpts(curve=0.1,
                                               width=1,
                                               color='#1685a9'),  # 连线的宽度与颜色
             effect_opts=opts.EffectOpts(is_show=False))  # 关闭涟漪效果
         .set_series_opts(label_opts=opts.LabelOpts(
             is_show=False)).set_global_opts(title_opts=opts.TitleOpts(
                 title="【%s】民航班机航线图" % self.name,
                 subtitle='{}共有直飞全国{}个城市的航班'.format(self.name, count))))
     return c
Beispiel #22
0
def get_gridbmap(message) -> BMap:
    BAIDU_AK = "HOTBRAfU1jGcQKHBX15ucKsfZO722eyN"
    pos = (117.20, 39.12)
    #jscode = "console.log('hi hi');"#可嵌入jscode
    #jscode = "functions(param){bmap.addEventListener('click', function(e){alert(e.point.lng + ','+ e.point.lat);});}"
    #每两个点画一条线
    j = [[{
        "coord": [117.20, 39.12]
    }, {
        "coord": [118.21, 41.12]
    }], [{
        "coord": [119.21, 41.12]
    }, {
        "coord": [115.21, 41.12]
    }]]
    c = (
        BMap().add_schema(
            baidu_ak=BAIDU_AK, center=[117.20, 39.12], zoom=12).add(
                "",
                type_="lines",
                data_pair=j,
                is_polyline=True,
                is_large=False,
                linestyle_opts=opts.LineStyleOpts(color="purple",
                                                  opacity=0.6,
                                                  width=1),
            ).set_series_opts(effect_opts=opts.EffectOpts(is_show=False),
                              label_opts=opts.LabelOpts(is_show=False)).
        add_control_panel(
            scale_control_opts=opts.BMapScaleControlOpts(),
            navigation_control_opts=opts.BMapNavigationControlOpts(),
            maptype_control_opts=opts.BMapTypeControlOpts(),
            #copyright_control_opts=opts.BMapCopyrightTypeOpts(copyright_="我的")
            #geo_location_control_opts=opts.BMapGeoLocationControlOpts()
            #overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
        )
        #.add_js_funcs(jscode)
        #.set_global_opts(title_opts=opts.TitleOpts(title="BMap-基本示例"))
    )
    return c
Beispiel #23
0
def geo_ip() -> Bar:
    # 连接数据库
    print("geo_ip")
    db = getattr(g, "_db", None)
    col = db.trafficmodels
    # 获取前端的传参user
    user = request.args.get("user")
    begintime = request.args.get("beginTime")
    successtime = request.args.get("successtime")
    # 如果没有指定用户,那么就返回第一个用户
    if (user is None) | (user == "-1"):
        user = col.find_one()["user"]
    if begintime is None:
        begintime = ""
    if successtime is None:
        successtime = ""
        # 在这里进行判断,应该用什么样的查询语句
        # 1.    用户名不为空,开始时间为空 ,上报时间为空
    place = col.find_one({"user": user}, {"place": 1})["place"]
    places = get_all_IP(user, begintime, successtime)
    print("geo_ip")
    list_place = []
    for p in places:
        list_place.append([place, p])
    c = (Geo().add_schema(maptype="world").add_coordinate_json(
        json_file="world_country.json").add(
            "目的IP位置",
            list_place,
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.DIAMOND,
                                        symbol_size=6,
                                        color="blue"),
            linestyle_opts=opts.LineStyleOpts(
                curve=0.2,
                opacity=0.2,
            )).set_series_opts(label_opts=opts.LabelOpts(
                is_show=False)).set_global_opts(
                    title_opts=opts.TitleOpts(title="目的IP交互图"),
                    tooltip_opts=opts.TooltipOpts(is_show=True)))
    return c
Beispiel #24
0
def get_bmap(pos) -> BMap:
    BAIDU_AK = "HOTBRAfU1jGcQKHBX15ucKsfZO722eyN"
    #center = (117.20, 39.12)
    c = BMap()
    c.add_schema(baidu_ak=BAIDU_AK,
                 center=[117.20, 39.12],
                 zoom=10,
                 is_roam=False)
    sequence = []
    for i in range(len(pos)):
        #print(pos[i])
        c.add_coordinate(pos[i][0], pos[i][2], pos[i][1])
        sequence.append((str(i), 5))
    c.add(
        "投诉坐标",  #系列名称
        sequence,
        type_="scatter",  #"heatmap" 可以切换显示的类型热力图或散点图
        label_opts=opts.LabelOpts(formatter="{b}"),
        symbol_size=4  #scatter大小
    )
    #.add("bmap",
    #[{"coord":[117.21, 39.13],"sim":10},{"coord":[117.20, 39.13],"sim":20},{"coord":[117.21, 39.12],"sim":5}],
    #[list(z) for z in zip(Faker.provinces, Faker.values())],#zip将迭代对像打包成元组最后的结果是[['浙江',v1],['广东',v2]]
    #[[117.21, 39.13],[117.20, 39.12],[117.22, 39.10],[117.25, 39.11],[117.19, 39.02],[117.20, 39.12]],
    #type_="heatmap",
    #label_opts=opts.LabelOpts(formatter="{b}"))
    c.set_series_opts(
        effect_opts=opts.EffectOpts(is_show=True),
        label_opts=opts.LabelOpts(is_show=False),
    )
    c.add_control_panel(
        scale_control_opts=opts.BMapScaleControlOpts(),
        navigation_control_opts=opts.BMapNavigationControlOpts(),
        maptype_control_opts=opts.BMapTypeControlOpts())
    #copyright_control_opts=opts.BMapCopyrightTypeOpts(copyright_="我的")
    #geo_location_control_opts=opts.BMapGeoLocationControlOpts()
    #overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
    #c.set_global_opts(visualmap_opts=opts.VisualMapOpts(pos_left="right"))
    return c
    def get_geo(self):
        china_total = "确诊:"+ str(self.all_data['chinaTotal']['confirm']) + \
                    " 疑似:" +str( self.all_data['chinaTotal']['suspect']) + \
                    " 死亡:" + str( self.all_data['chinaTotal']['dead']) +  \
                    " 治愈:" +  str(self.all_data['chinaTotal']['heal']) + \
                    " 更新日期:" + str(self.all_data['lastUpdateTime'])

        geo = (
            Geo(init_opts=opts.InitOpts(width="1200px",
                                        height="600px",
                                        bg_color="#404a59",
                                        page_title="全国疫情实时报告",
                                        renderer=RenderType.SVG,
                                        theme="white"))  #设置绘图尺寸,背景色,页面标题,绘制类型
            .add_schema(maptype="china",
                        itemstyle_opts=opts.ItemStyleOpts(
                            color="rgb(49,60,72)",
                            border_color="rgb(0,0,0)"))  #中国地图,地图区域颜色,区域边界颜色
            .add(series_name="geo",
                 data_pair=self.data_pair,
                 type_=GeoType.EFFECT_SCATTER)  #设置地图数据,动画方式为涟漪特效effect scatter
            .set_series_opts(  #设置系列配置
                label_opts=opts.LabelOpts(is_show=False),  #不显示Label
                effect_opts=opts.EffectOpts(scale=6))  #设置涟漪特效缩放比例
            .set_global_opts(  #设置全局系列配置
                visualmap_opts=opts.VisualMapOpts(min_=0,
                                                  max_=100),  #设置视觉映像配置,最大值为平均值
                title_opts=opts.TitleOpts(
                    title="全国疫情地图",
                    subtitle=china_total,
                    pos_left="center",
                    pos_top="10px",
                    title_textstyle_opts=opts.TextStyleOpts(
                        color="#fff")),  #设置标题,副标题,标题位置,文字颜色
                legend_opts=opts.LegendOpts(is_show=False),  #不显示图例
            ))

        return geo
Beispiel #26
0
def in_data(city, date_number):
    workbook = xlrd.open_workbook(f'.\\{path}\\{city}-迁入来源地规模指数.xlsx')
    sheet = workbook.sheet_by_index(0)
    city_od_list = []
    city_od_values = []
    a = 0
    cols = sheet.col_values(1)[1:]
    cols_date = sheet.col_values(date_number + 1)[1:]
    for j in cols:
        city_od = (j, city)
        city_od_v = (j, cols_date[a])
        city_od_list.append(city_od)
        city_od_values.append(city_od_v)
        a += 1
    geo = Geo()
    # 地图类型,世界地图可换为world
    geo.add_schema(maptype="广西")
    # 添加数据点
    geo.add("%", city_od_values, type_=ChartType.EFFECT_SCATTER)
    # 添加流向,type_设置为LINES,涟漪配置为箭头,提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle',
    # 'diamond', 'pin', 'arrow', 'none'
    geo.add("迁入城市",
            city_od_list,
            type_=ChartType.LINES,
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                        symbol_size=5,
                                        color="yellow"),
            linestyle_opts=opts.LineStyleOpts(curve=0.2),
            is_large=True)
    # 不显示标签
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    # 设置图标标题,visualmap_opts=opts.VisualMapOpts()为左下角的视觉映射配置项
    geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(),
                        title_opts=opts.TitleOpts(title=f"{city}迁入数据"))
    # 直接在notebook里显示图表
    geo.render_notebook()
    # 生成html文件,可传入位置参数
    geo.render(f".\\in_od\\{city}-2020.10.{date_number}迁入OD图.html")
Beispiel #27
0
 def map_line_test(self, num_city_list, city_list):
     c = (
         Geo(init_opts=opts.InitOpts(theme=ThemeType.DARK, width="800px"))
         .add_schema(maptype="china")
         .add(
             "",
             num_city_list,
             type_=ChartType.EFFECT_SCATTER,
             color="blue",
         )
         .add(
             "2019下半年出差路线图",
             city_list,
             type_=ChartType.LINES,
             effect_opts=opts.EffectOpts(
                 symbol=SymbolType.TRIANGLE, symbol_size=6, color="Lime"
             ),
             linestyle_opts=opts.LineStyleOpts(curve=0.3, color="green"),
         )
         .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
         .set_global_opts(title_opts=opts.TitleOpts(title="出差路线图"))
     )
     return c
Beispiel #28
0
def geo_getmap() -> Geo:

    c = (Geo().add_schema(
        maptype="china",
        itemstyle_opts=opts.ItemStyleOpts(color="#323c48",
                                          border_color="#111"),
    ).add(
        "",
        allcases,
        type_=ChartType.EFFECT_SCATTER,
        color="white",
    ).add(
        "",
        traces,
        type_=ChartType.LINES,
        effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                    symbol_size=6,
                                    color="red"),
        linestyle_opts=opts.LineStyleOpts(curve=0.2),
    ).set_series_opts(label_opts=opts.LabelOpts(
        is_show=False)).set_global_opts(title_opts=opts.TitleOpts(
            title="2019-nCoV Trace Map(China)")))
    make_snapshot(snapshot, c.render(), "tracemap.png")
Beispiel #29
0
def get_mymap(message) -> Geo:
    pos = (117.20, 39.12)
    tianjing_map = (
        Geo().add_schema(maptype="北京", is_roam=False)
        # 加入自定义的点,格式为
        #.add_coordinate("测试点", pos[0],pos[1])
        #.add(
        #    "测试点",[("测试点", 51)],type_="effectScatter",
        #    label_opts=opts.LabelOpts(formatter="{b}"),
        #)
        #.add_coordinate_json("./demo/coord.json")
        # 为自定义的点添加属性
        #.add("测试点",[("测试点", 51)],type_="effectScatter")
        .add("bmap", [list(z) for z in zip(Faker.provinces, Faker.values())],
             type_="heatmap",
             label_opts=opts.LabelOpts(formatter="{b}"))
        #.set_series_opts()
        .set_series_opts(
            label_opts=opts.LabelOpts(is_show=False),
            effect_opts=opts.EffectOpts(is_show=True)).set_global_opts(
                title_opts=opts.TitleOpts(title=message,
                                          pos_right="center"), ))
    return tianjing_map
Beispiel #30
0
                    title_opts=opts.TitleOpts(title="Geo-流向图"))
#添加主题,中国地图,填充及边界颜色设置
geo.add_schema(
            maptype="china",
            itemstyle_opts=opts.ItemStyleOpts( border_color="#111", color="#454545"),
        )
#添加系列
geo.add(
            "",
            [("成都",10),("合肥",20),("宁波",30),("武汉",40),("西安",50),("郑州",60),("大连",70),("济南",80)],
            type_=ChartType.EFFECT_SCATTER,             #散点图的一种形式
            label_opts=opts.LabelOpts(is_show = True),   #不显示数值则设置为False
          #  color="red"
        )
geo.add(
            "",
            [("北京", 100), ("上海", 100)],
            type_=ChartType.HEATMAP,       #散点的另一种形式
            label_opts=opts.LabelOpts(is_show=False)
        )
#设置流向
geo.add(
            "流向图",
            [("上海","成都"),("上海","合肥"),("上海","宁波"),("上海","武汉"),("上海","西安"),("北京","郑州"),("北京","大连"),("北京","济南")],
            type_=ChartType.LINES,
            linestyle_opts=opts.LineStyleOpts(curve=0.3,color="#63B8FF"),   #基本线条的弯曲程度及颜色,英文及RGB都行
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW, symbol_size=6, color="#FF7F00")  # 流向线条的形式、颜色
        )
#生成图片
geo.render('geo1.html')