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')
예제 #2
0
파일: plot.py 프로젝트: AnonymKing/snmp
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")
예제 #3
0
def generate_geo_png(geodata, geomax, geomin, geotitle, display_id,
                     map_data_title):
    from pyecharts import options as opts
    from pyecharts.charts import Map, Geo
    from pyecharts.render import make_snapshot
    # from pyecharts_snapshot.main import make_a_snapshot
    from snapshot_selenium import snapshot
    geo = Geo()
    geo.add_coordinate_json(
        '/home/CitizenScience/backend/backend/geoCoordJson.js')
    geo.add_schema(maptype="china")
    print(geodata)
    print(map_data_title)
    geo.add(" ", geodata, symbol_size=10)
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(
        visualmap_opts=opts.VisualMapOpts(max_=geomax, min_=geomin))
    figure_url = "/home/CitizenScience/file/visualization/" + str(
        display_id) + '_geo.png'
    # figure_url = str(display_id) + '_geo.png'
    make_snapshot(snapshot, geo.render(), figure_url, 2)
    # geo.render(path='render.html')
    # cmd = "snapshot render.html png"
    # try:
    #    isRun = os.system(cmd)
    #    print("截图完成")
    # except:
    #    print("截图失败")
    # cmd = "mv output.png ../file/visualization/{}".format(figure_url)
    # try:
    #     isRun = os.system(cmd)
    #    print("移动完成")
    # except:
    #     print("移动失败")

    # make_a_snapshot('geo2.html', 'geo3.png')
    return figure_url
예제 #4
0
파일: util.py 프로젝트: perry-xy/SF
class NetworkVisualization(object):
    """
    class which show the demand heat map and the allocation network
    """
    def __init__(self, data_class, json_file=None):
        """
        Initialization the class with data_class and json_file parameters, and add the customized city into Geo class
        :param data_class: the data_class
        :param json_file:
        """
        self.geo = Geo()
        self.data_class = data_class
        self.json_file = json_file
        if self.json_file is not None:
            self._load_coordinate_json()
        else:
            if not hasattr(self.data_class, 'city'):
                raise ValueError(
                    'the city and corresponding longitude and latitude should be included in data_class!'
                )
            else:
                self._load_coordinate()

    def _load_coordinate(self):
        # add the customized city with the corresponding longitude and latitude
        if len(self.data_class.city) != len(self.data_class.longitude):
            raise ValueError(
                'the length of city and longitude and latitude should be same !'
            )
        for city, longitude, latitude in zip(self.data_class.city,
                                             self.data_class.longitude,
                                             self.data_class.latitude):
            self.geo.add_coordinate(city, longitude, latitude)

    def _load_coordinate_json(self):
        # add the customized city with the longitude and latitude json file to Geo
        # json file contents: { 'city name':[120.123,32.345] }
        self.geo.add_coordinate_json(self.json_file)

    def heat_map(self, city, demand) -> Geo:
        c = (Geo().add_schema(maptype="china").add(
            "demand heat map ", [list(z) for z in zip(city, demand)],
            type_=ChartType.HEATMAP,
            symbol_size=8).set_series_opts(label_opts=opts.LabelOpts(
                is_show=False)).set_global_opts(
                    visualmap_opts=opts.VisualMapOpts(max_=max(demand) * 1.2),
                    title_opts=opts.TitleOpts(title="demand heat map "),
                ))
        return c

    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