Esempio n. 1
0
File: test.py Progetto: pipoted/bs
def creat_lan_charts(data_list):
    page = Page()
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#404a59')

    chart = Geo("python", "python-city", **style.init_style)
    attr, value = chart.cast(data_list)
    chart.add("",
              attr,
              value,
              visual_range=[0, 200],
              visual_text_color="#fff",
              is_legend_show=False,
              symbol_size=15,
              is_visualmap=True,
              tooltip_formatter='{b}',
              label_emphasis_textsize=15,
              label_emphasis_pos='right')
    page.add(chart)

    chart = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
    attr, value = chart.cast(data_list)
    chart.add("",
              attr,
              value,
              type="heatmap",
              is_visualmap=True,
              visual_range=[0, 200],
              visual_text_color='#fff',
              is_legend_show=False)
    page.add(chart)
    return page
Esempio n. 2
0
    def draw1(self,time = None):
        global local

        # some city cannot by process by echart
        echart_unsupported_city = [
        "菏泽市", "襄阳市", "恩施州", "湘西州","阿坝州", "延边州",
        "甘孜州", "凉山州", "黔西南州", "黔东南州", "黔南州", "普洱市", "楚雄州", "红河州",
        "文山州", "西双版纳州", "大理州", "德宏州", "怒江州", "迪庆州", "昌都市", "山南市",
        "林芝市", "临夏州", "甘南州", "海北州", "黄南州", "海南州", "果洛州", "玉树州", "海西州",
        "昌吉州", "博州", "克州", "伊犁哈萨克州"]
        if time is None and len(df_aqi) > 0:
            time = df_aqi['time'][0]
        data = []
        for index, row in df_aqi.iterrows():
            city = row['city']
            aqi = row['aqi']
            if city=='长沙市':
                print(city)
                localAQI=aqi
            if city in echart_unsupported_city:
                continue
            data.append( (city, aqi) )
        
        #lcaqi=''.join(localAQI)
        #print(lcaqi)
        if localAQI<70:
            geo = Geo("全国最新主要城市空气质量(AQI) \n 当前城市:长沙 AQI:%s \n \n您在的城市不错,不开心的话,也出去走走吧" % localAQI, "数据来源于环保部网站",
                     title_color="#fff",
                     title_pos="center", width=425,
                     height=730, background_color='#404a59')
        else:
            geo = Geo("全国最新主要城市空气质量(AQI) \n 当前城市:长沙 AQI:%s \n \n环境很差!!出去走走吧,已经为您规划路线" % localAQI, "数据来源于环保部网站",
                     title_color="#fff",
                     title_pos="center", width=425,
                     height=730, background_color='#404a59')
                 
        attr, value = geo.cast(data)
        
        geo.add("", attr, value, visual_range=[0, 150],
            maptype='china',visual_text_color="#fff",
            symbol_size=10, is_visualmap=True,
            label_formatter='{b}', # 指定 label 只显示城市名
            tooltip_formatter='{c}', # 格式:经度、纬度、值
            label_emphasis_textsize=15, # 指定标签选中高亮时字体大小
            label_emphasis_pos='right' # 指定标签选中高亮时字体位置
            )
        #print(data)
        geo.render('aqi.html')
        self.webView.load(QUrl("file:///D:/源代码/aqi.html"))

        #self.webView.reload()
        self.webView.repaint()
        self.webView.update()
Esempio n. 3
0
def generate_heatmap(title):
    data = [(city_com['city'][i], city_com['count'][i])
            for i in range(0, city_com.shape[0])]
    geo = Geo(title,
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    attr_list = []
    value_list = []
    len = attr.__len__()
    for i in range(len):
        try:
            attr_list.append(attr[i])
            value_list.append(value[i])
            geo.add("city",
                    attr_list,
                    value_list,
                    visual_range=[0, 200],
                    maptype='heatmap',
                    visual_text_color="#000",
                    symbol_size=10,
                    is_visualmap=True)

        except ValueError as e:
            print(e)
            attr_list.remove(attr[i])
            value_list.remove(value[i])
            continue

    geo = Geo(title,
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404b59')
    geo.add("city",
            attr_list,
            value_list,
            visual_range=[0, 3500],
            maptype='china',
            border_color='fff',
            visual_text_color="#fff",
            symbol_size=5,
            is_visualmap=True)
    # geo.show_config()
    geo.render('resources/heat_map.html')
Esempio n. 4
0
def geo_test(a, b):
    attr = pd.Series(unique(a)).values
    value = pd.Series(b.groupby(a).count()).values
    data = [("上海", 47647), ("北京", 21454), ("南京", 849), ("南充", 15745),
            ("南通", 16352), ("合肥", 11895), ("广州", 43589), ("延安", 3180),
            ("成都", 19979), ("杭州", 33143), ("武汉", 6465), ("沧州", 13223),
            ("深圳", 31281), ("湖州", 22433), ("牡丹江", 20526), ("西安", 30548),
            ("金华", 22799), ("阜阳", 12004)]
    geo = Geo("全国各个城市的门店分布",
              "数据来源:香飘飘-饿了么爬虫原始数据",
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color="#404a59")
    attr_x, value_y = geo.cast(data)
    geo.add("",
            attr_x,
            value_y,
            visual_range=[0, 200],
            visual_text_color="#fff",
            symbol_size=15,
            is_visualmap=True)
    geo.show_config()
    geo.render("E:\\py_data_html\\ele_data_2.html")
    geo
def geographical_location_distribution():
    data = pd.read_csv(filepath, encoding='gbk')
    data['salary'] = data['salary'].apply(lambda xx: re.sub(u'k|K|以上', '', xx))
    data['min_salary'] = data['salary'].apply(
        lambda xx: float(xx.split('-')[0]) * 1000)
    data['max_salary'] = data['salary'].apply(
        lambda xx: float(xx.split('-')[1]) * 1000
        if len(xx.split('-')) > 1 else float(xx) * 1000)
    # print  data[data['min_salary'] == data['max_salary']]  ##  xx以上
    dataset = [(city, min_salary)
               for city, min_salary in data['city min_salary'.split()].values]

    geo = Geo("Python Job Distribution",
              "",
              title_pos="center",
              width=2000,
              height=1200,
              background_color='#404a59')
    attr, value = geo.cast(dataset)
    geo.add("",
            attr,
            value,
            type="effectScatter",
            is_visualmap=True,
            maptype='china',
            visual_range=[0, 300],
            effect_scale=5,
            symbol_size=5,
            visual_text_color="#fff")

    geo.render(filedir + 'job_distribution.html')
Esempio n. 6
0
def heat_map():
    data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14),
            ("盐城", 15), ("赤峰", 16), ("青岛", 18), ("乳山", 18), ("金昌", 19),
            ("泉州", 21), ("莱西", 21), ("日照", 21), ("胶南", 22), ("南通", 23),
            ("拉萨", 24), ("云浮", 24), ("梅州", 25), ("乌鲁木齐", 40)]

    geo = Geo("全国主要城市空气质量热力图",
              "data from pm2.5",
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)

    geo.add("空气质量热力图",
            attr,
            value,
            visual_range=[0, max(value)],
            type='heatmap',
            visual_text_color="#fff",
            symbol_size=15,
            is_label_show=True,
            is_visualmap=True)
    # geo.show_config()

    geo.render(path="./data/空气质量热力图.html")
def area_condition(get_all_data):
    get_all_data = get_all_data["work_place"].value_counts()
    del get_all_data['香港特别行政区']
    del get_all_data['澳门特别行政区']
    del get_all_data['庆阳']
    del get_all_data['延边']
    geo = Geo("城市分布情况",
                  title_color="#fff",
                  title_pos="center",
                  width = 800,
                  height = 800,
                  background_color="#404a59")


    attr = get_all_data.index
    value = get_all_data.values
    
    geo.add("",
            attr,
            value,
            type = "effectScatter",
            visual_range=[0,400],
            maptype="china",
            visual_text_color = "#fff",
            geo_normal_color = "#080808",
            geo_emphasis_color = "#FFFF00",
            symbol_size= 6,
            border_color = "#FFFFFF",
            effect_scale = 5,
            is_visualmap=True,
            is_roam = True)
    geo.render("C:/WeSite/DataCharts/岗位概况/岗位-城市分布图.html",pixel_ratio=0.5)
    geo.render("C:/WeSite/DataCharts/岗位概况/岗位-城市分布图.png",pixel_ratio=0.5)
Esempio n. 8
0
def test_geo_visualmap_pieces():
    data = [
        ("海门", 9),
        ("鄂尔多斯", 12),
        ("招远", 12),
        ("舟山", 12),
        ("齐齐哈尔", 14),
        ("盐城", 15),
    ]
    geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
    attr, value = geo.cast(data)
    geo.add(
        "",
        attr,
        value,
        type="effectScatter",
        is_random=True,
        is_visualmap=True,
        is_piecewise=True,
        visual_text_color="#fff",
        pieces=[
            {"min": 0, "max": 13, "label": "0 < x < 13"},
            {"min": 14, "max": 16, "label": "14 < x < 16"},
        ],
        effect_scale=5,
    )
    content = geo._repr_html_()
    assert '"max": 13' in content
    assert '"label": "14 < x < 16"' in content
Esempio n. 9
0
def render():
    #获取所在城市
    cities = []
    with io.open('friends.txt', mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows:
            city = row.split(',')[3]
            if city != '':
                cities.append(city)

    handle(cities)

    data = Counter(cities).most_common()
    #print(data)

    #绘执地理坐标图
    geo = Geo("好友位置分布",
              '',
              title_color='#fff',
              title_pos='center',
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    geo.add('',
            attr,
            value,
            visual_range=[0, 500],
            visual_text_color='#fff',
            symbol_size=15,
            is_visualmap=True,
            is_piecewise=True)
    geo.render('好友位置分布.html')
Esempio n. 10
0
    def getView(self):
        db = DBUtils()
        sql = 'select city from comment'
        city = db.selectallInfo(sql)
        print(city)
        for i in city:
            citys.append(i[0])
        data = []
        for item in self.all_list(citys):
            data.append((item, self.all_list(citys)[item]))
        style = Style(title_color="#fff",
                      title_pos="center",
                      width=950,
                      height=650,
                      background_color="#404a59")

        geo = Geo("《西红市首富》粉丝人群地理位置", "刘宏伟", **style.init_style)

        attr, value = geo.cast(data)

        geo.add("",
                attr,
                value,
                visual_range=[
                    0,
                ],
                visual_text_color="#fff",
                symbol_size=20,
                is_visualmap=True,
                is_piecewise=True,
                visual_split_number=5)
        geo.render('../templates/render.html')
Esempio n. 11
0
def test_geo_china_scatter(patched):
    fixture = "geo_options.json"
    patched.return_value = "1"
    cities = [("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)]
    geo = Geo("全国主要城市空气质量", "data from pm2.5")
    attr, value = geo.cast(cities)
    geo.add(
        "",
        attr,
        value,
        visual_range=[0, 200],
        visual_text_color="#fff",
        is_legend_show=False,
        symbol_size=15,
        is_visualmap=True,
        tooltip_formatter="{b}",
        label_emphasis_textsize=15,
        label_emphasis_pos="right",
    )
    actual_options = json.dumps(geo.options,
                                sort_keys=True,
                                indent=4,
                                cls=DefaultJsonEncoder)
    expected = get_fixture_content(fixture)
    for a, b in zip(actual_options.split("\n"), expected.split("\n")):
        eq_(a.strip(), b.strip())
Esempio n. 12
0
def plot():
    for item in all_list(city):

        data.append((item, all_list(city)[item]))

        style = Style(title_color="#fff",
                      title_pos="center",
                      width=1200,
                      height=600,
                      background_color="#404a59")

    geo = Geo("《邪不压正》粉丝人群地理位置", "数据来源:量子皮皮马", **style.init_style)

    attr, value = geo.cast(data)

    geo.add("",
            attr,
            value,
            visual_range=[0, 20],
            visual_text_color="#fff",
            symbol_size=20,
            is_visualmap=True,
            is_piecewise=True,
            visual_split_number=4)
    geo.render("plot.html")
Esempio n. 13
0
def create_geo_charts(data, title):
    '''地图'''
    page = Page()
    # 样式
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#c4ccd3')
    # 创建地图模型
    chart = Geo(title, "", **style.init_style)
    # 数据 ['上海', '北京', '广州', '深圳', '苏州'] [5, 40, 10, 15, 5]
    attr, value = chart.cast(data)
    # 添加数据
    chart.add("",
              attr,
              value,
              maptype='china',
              is_visualmap=True,
              type="effectScatter",
              is_legend_show=False,
              geo_emphasis_color='c4ccd3',
              visual_text_color='#2f4554')

    page.add(chart)

    return page
Esempio n. 14
0
def draw_map(comments):
    try:
        attr = comments['cityName'].fillna("zero_token")
        data = Counter(attr).most_common(100)
        #data.remove(data[data.index([(i, x) for i, x in (data) if i == 'zero_token'][0])])

        geo = Geo("《毒液》观众位置分布",
                  "数据来源:猫眼电影 - SmartCrane采集",
                  title_color="#fff",
                  title_pos="center",
                  width=1000,
                  height=600,
                  background_color='#404a59')
        attr, value = geo.cast(data)
        geo.add("",
                attr,
                value,
                visual_range=[0, 1000],
                maptype='china',
                visual_text_color="#fff",
                symbol_size=10,
                is_visualmap=True)
        geo.render("./观众位置分布-地理坐标图.html")  # 生成html文件
        geo  # 直接在notebook中显示
    except Exception as e:
        print(e)
Esempio n. 15
0
def draw_timezone_map(df, map_html):
    geo = Geo("星巴克时区分布地图",
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=500,
              background_color='#404a59')
    geo_cities_coords = {
        df.iloc[i]['Store Name']: [df.iloc[i]['lon'], df.iloc[i]['lat']]
        for i in range(len(df))
    }
    attr = list(df['Store Name'])
    value = list(df['timezone_amount'])
    geo.add("",
            attr,
            value,
            visual_text_color="#fff",
            maptype="world",
            visual_range=[0, 2000],
            is_visualmap=True,
            symbol_size=5,
            center=(-121, 38.5),
            tooltip_formatter=geo_formatter,
            geo_cities_coords=geo_cities_coords)
    geo.render(map_html)
Esempio n. 16
0
def draw_map(df, map_html):
    geo = Geo("星巴克店铺分布图",
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=500,
              background_color='#404a59')

    geo_cities_coords = {
        df.iloc[i]['Store Name']: [df.iloc[i]['lon'], df.iloc[i]['lat']]
        for i in range(len(df))
    }
    value = list(df['Average Score'])
    attr = list(df['Store Name'])

    geo.add("",
            attr,
            value,
            visual_range=[0, 10],
            visual_text_color="#fff",
            visual_split_number=5,
            maptype="world",
            is_visualmap=True,
            is_piecewise=True,
            geo_formatter=geo_formatter,
            symbol_size=5,
            center=(113, 23),
            geo_cities_coords=geo_cities_coords)
    geo.render(map_html)
Esempio n. 17
0
def get_map(data):
    print(data)
    geo = Geo(
        "全国必胜客城市分布",
        "data from pizzahut",
        title_color="#fff",
        title_pos="center",
        width=1200,
        height=600,
        background_color="#404a59",
    )
    try:
        attr, value = geo.cast(data)
        geo.add(
            "",
            attr,
            value,
            visual_range=[0, 200],
            visual_text_color="#fff",
            symbol_size=10,
            is_roam=True,
            is_visualmap=True,
        )
        geo.render()
    except ValueError as info:
        error_city = str(info).split(' ')[-1]
        print(error_city)
        dict = {k: v for k, v in data}
        print((error_city, dict[error_city]))
        data.remove((error_city, dict[error_city]))
        get_map(data=data)
Esempio n. 18
0
def mGeoAll(df, minit):
    df.dropna(axis=0, how='any', inplace=True)
    print(df.head())
    attr = list(df['city'])
    value = list(df['count'])

    geo = Geo(
        "全国油站数量分布",
        title_color="#fff",
        title_pos="center",
        width=1200,
        height=600,
        background_color="#404a59",
    )
    range_max = max(value)
    geo.add(
        "",
        attr,
        value,
        visual_range=[0, range_max],
        visual_text_color="#fff",
        #            symbol_size=15,
        is_visualmap=True,
    )
    geo.render('全国油站数量分布.html')
Esempio n. 19
0
def geo_qgtd(attr_v1: List[Tuple[str, int]], chart_name: str,
             v1_name: str) -> geo.Geo:
    """
    生成全国地图-数据通道图
    :param attr_v1: 主要数据
    :param chart_name: 图表名
    :param v1_name: 数据一名
    """
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=900,
                  height=600,
                  background_color='#404a59')
    # chart = Map(chart_name, **style.init_style)
    # chart.add(v1_name, attr, value, maptype='china', is_visualmap=True,
    #           visual_text_color='#000')
    chart = Geo(chart_name, "", **style.init_style)
    attr, value = chart.cast(attr_v1)
    chart.add(v1_name,
              attr,
              value,
              visual_range=[0, 70000],
              visual_text_color="#fff",
              is_legend_show=False,
              symbol_size=15,
              is_visualmap=True,
              tooltip_formatter='{b}',
              label_emphasis_textsize=15,
              label_emphasis_pos='right',
              type='effectScatter')

    return chart
Esempio n. 20
0
def plt_place(place, htmlfile):
    city_name, city_list = clean_cities_name(place)  # 对城市名进行清理
    city_dict = {city_list[i]: 0 for i in range(len(city_list))}
    for i in range(len(city_list)):
        city_dict[city_list[i]] = city_name.count(city_list[i])
    print(city_dict)
    # 根据数量排序
    sort_dict = sorted(city_dict.items(), key=lambda d: d[1], reverse=True)
    city_name = []
    city_num = []
    for i in range(len(sort_dict)):
        city_name.append(sort_dict[i][0])
        city_num.append(sort_dict[i][1])
    data = list(zip(city_name, city_num))
    geo = Geo("评论者位置分布",
              "数据来源知乎",
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    # 注意修改显示范围
    geo.add('城市',
            attr,
            value,
            visual_range=[0, 20],
            visual_text_color='#fff',
            symbol_size=10,
            is_visualmap=True,
            is_picewise=False,
            visual_split_number=10)
    geo.render(htmlfile)
Esempio n. 21
0
def gen_price_map(year=None, month=None, province='china'):
    # 绘制地区温度图
    house_db = HouseDatabase('residential')
    year_cond = 'year=%d' % year if year is not None else ''
    month_cond = ' and month=%d' % month if month is not None else ''
    province_cond = " and province='%s'" % province if province not in [
        'china', '中国'
    ] else ''
    condition = year_cond + month_cond + province_cond
    latest_price = house_db.query_records(condition)
    cities_prices = [(item['city'], item['price']) for item in latest_price
                     if item['city'] not in STOP_CITY]
    geo = Geo("",
              '',
              title_color="#fff",
              title_pos="left",
              background_color='#404a59')  # width=1000, height=600,
    cities, prices = geo.cast(cities_prices)
    geo.add('%d-%d' % (NOW.year, NOW.month),
            cities,
            prices,
            maptype=province,
            type="heatmap",
            is_visualmap=True,
            visual_range=[numpy.min(prices),
                          numpy.max(prices)],
            visual_text_color="#fff")
    geo.render("./out/房价温度图-%s.html" %
               condition.replace(' and ', '-').replace('=', '_'))
Esempio n. 22
0
def render_city(cities):
    # 对城市数据和坐标文件中的地名进行处理
    handle(cities)
    data = Counter(cities).most_common()  # 使用Counter类统计出现的次数,并转换为元组列表
    print(data)

    # 定义样式
    style = Style(title_color='#fff',
                  title_pos='center',
                  width=1200,
                  height=600,
                  background_color='#404a59')

    # 根据城市数据生成地理坐标图
    geo = Geo('《悲伤逆流成河》粉丝位置分布', **style.init_style)
    attr, value = geo.cast(data)
    geo.add('',
            attr,
            value,
            visual_range=[0, 600],
            visual_text_color='#fff',
            symbol_size=15,
            is_visualmap=True,
            is_piecewise=True,
            visual_split_number=10)
    geo.render(d + '/picture/geo.html')
Esempio n. 23
0
    def place2(self):
        City = []  # 微信好友所在城市
        for city in self.friends[1:]:
            # if city['City']=="东城":
            #     print(city)
            #     return
            City.append(city['City'])
        print(City)
        Citys = collections.Counter(City)  # 每个城市对应的数量

        values = []  # weixin2 Map
        for city in set(City):  # values 每个城市对应的数量
            if (city != '' and city.isalpha()):  # 除去没有城市的 和 外国城市
                values.append((city, Citys[city]))
        print(values)

        geo = Geo(u"%s 各省微信好友分布" % self.nickName,
                  u"冀祥",
                  title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#404a59')
        attr, value = geo.cast(values)
        print(attr, value)
        geo.add("",
                attr,
                value,
                visual_range=[0, 200],
                visual_text_color="#fff",
                symbol_size=15,
                is_visualmap=True)
        #  geo.show_config()
        geo.render("%s的好友分部图2.html" % self.nickName)
Esempio n. 24
0
def echarts_draw(locations, fileName, path="./", title="地域分布图"
                 , subtitle="location distribute"):
    
    """
    生成地域分布的echarts热力图的html文件.
    :param locations: 样本的省市区, pandas的dataframe类型.
    :param fileName: 生成的html文件的文件名.
    :param path: 生成的html文件的路径.
    :param title: 图表的标题
    :param subtitle: 图表的子标题
    """
    from pyecharts import Geo
    
    _base_input_check(locations)
    map_keys = locations["省"] + "," + locations["市"] + "," + locations["区"]
    count_map = {}
    from .infrastructure import SuperMap
    for map_key in map_keys:
        if SuperMap.lat_lon_mapper.get(map_key):
            count_map[map_key] = count_map.get(map_key, 0) + 1
    
    geo = Geo(title, subtitle, title_color="#fff",
          title_pos="center", width=1200,
          height=600, background_color='#404a59')
    _geo_update(geo)
    attr, value = geo.cast(count_map)
    geo.add("", attr, value, type="heatmap", is_visualmap=True,
        visual_text_color='#fff',
        is_piecewise=True, visual_split_number=10)
    geo.render(path + fileName)
Esempio n. 25
0
def draw_map(comments):
    try:
        attr = comments['cityName'].fillna("zero_token")
        data = Counter(attr).most_common(300)
        data.remove(data[data.index([(i, x) for i, x in (data)
                                     if i == 'zero_token'][0])])
        #print(data)
        geo = Geo("《Avengers:Endgame》全国观众地域分布",
                  "数据来源:猫眼电影",
                  title_color="#fff",
                  title_pos="center",
                  width=1450,
                  height=725,
                  background_color='#404a59')
        attr, value = geo.cast(data)
        geo.add("",
                attr,
                value,
                visual_range=[0, 1000],
                maptype='china',
                visual_text_color="#fff",
                symbol_size=10,
                is_visualmap=True)
        geo.render("./全国观众地域分布地理坐标图.html")
        print("全国观众地域分布已完成")
    except Exception as e:
        print(e)
def visualize(df, name):
    # 导入自定义的地点经纬度
    geo_cities_coords = {
        df.iloc[i]['poi_name']: [df.iloc[i]['lng'], df.iloc[i]['lat']]
        for i in range(len(df))
    }  # 根据文件大小生成字典
    attr = list(df['poi_name'])  # 字典的每个键值
    value = list(df['poi_porb'])  # 由于量值的太大,换算以下(散点的颜色就是和这个想关的)
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color="#404a59")

    # 可视化
    geo = Geo(name, **style.init_style)
    geo.add("",
            attr,
            value,
            visual_range=[0.2, 1],
            symbol_size=10,
            visual_text_color="#fff",
            is_piecewise=True,
            is_visualmap=True,
            maptype='北京',
            visual_split_number=10,
            geo_cities_coords=geo_cities_coords)
    return geo
Esempio n. 27
0
def create_map(data):
    geo = Geo('《无名之辈》观众位置分布', '数据来源:猫眼采集',
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color="#404a59")
    try:
        attr, value = geo.cast(data)
        geo.add(
            "",
            attr,
            value,
            visual_range=[0, 1000],
            visual_text_color="#fff",
            symbol_size=15,
            is_visualmap=True,
        )
        geo.render("观众位置分布-地理坐标图.html")
    except ValueError as info:
        error_city = str(info).split(' ')[-1]
        del data[error_city]
        create_map(data)
    data_top10 = Counter(data).most_common(10)
    print(data_top10)
    bar = Bar('无名之辈观众来源排行TOP10', '数据来源:猫眼', title_pos='center')
    attr, value = bar.cast(data_top10)
    bar.add('', attr, value, is_visualmap=True, visual_range=[0, 3500], visual_text_color='#fff', is_more_utils=True, \
            is_label_show=True)
    bar.render("观众来源排行榜-柱状图.html")
Esempio n. 28
0
def render():
    # 获取所有城市
    cities = []
    with open('friends.txt', mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows:
            city = row.split(',')[4]
            if city != '':  # 去掉城市名为空的值
                cities.append(city)

    # 对城市数据和坐标文件中的地名进行处理
    handle(cities)

    # 统计每个城市出现的次数
    data = Counter(cities).most_common()  # 使用Counter类统计出现的次数,并转换为元组列表
    print(data)

    # 根据城市数据生成地理坐标图
    geo = Geo('好友位置分布', '', title_color='#fff', title_pos='center', width=800, height=500,
              background_color='#404a59')
    attr, value = geo.cast(data)
    geo.add('', attr, value, visual_range=[0, 500],
            visual_text_color='#fff', symbol_size=15,
            is_visualmap=True, is_piecewise=True)
    geo.render('好友位置分布.html')

    # 根据城市数据生成柱状图
    data_top20 = Counter(cities).most_common(20)  # 返回出现次数最多的20条
    bar = Bar('好友所在城市TOP20', '', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data_top20)
    bar.add('', attr, value, is_visualmap=True, visual_text_color='#fff', is_more_utils=True,
            is_label_show=True)
    bar.render('好友所在城市TOP20.html')
Esempio n. 29
0
def heat_map_with_scatter():
    # 空气质量评分
    indexs = [
        '上海', '北京', '合肥', '哈尔滨', '广州', '成都', '无锡', '杭州', '武汉', '深圳', '西安',
        '郑州', '重庆', '长沙'
    ]
    values = [
        4.07, 1.85, 4.38, 2.21, 3.53, 4.37, 1.38, 4.29, 4.1, 1.31, 3.92, 4.47,
        2.40, 3.60
    ]

    geo = Geo("全国主要城市空气质量评分",
              "data from pm2.5",
              title_color="#fff",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404a59')
    # 图例类型,有'scatter', 'effectscatter', 'heatmap'可选。
    # type="effectScatter", is_random=True, effect_scale=5  使点具有发散性
    geo.add("空气质量评分",
            indexs,
            values,
            type="scatter",
            is_random=True,
            effect_scale=5,
            visual_range=[0, 5],
            visual_text_color="#fff",
            symbol_size=15,
            is_visualmap=True,
            is_roam=False)
    # geo.show_config()
    geo.render(path="./data/空气质量评分-scatter.html")
Esempio n. 30
0
def ShowNumWithYear(df):
    # show bus num in different year at different cities
    years = list(set(df['year']))
    years.sort()
    cities = []
    values = []
    total_num = 0
    geos = []  # store the geo every year
    timeline = Timeline(width=1500,height=800,is_auto_play=True, timeline_bottom=-10,timeline_symbol_size=20,\
        timeline_play_interval = 800,timeline_left=20,timeline_right=100 , is_timeline_show = False )
    for index in range(len(years)):
        df_temp = df[df['year'] == years[index]]
        cities = cities + list(df_temp['city'])
        values = values + list(df_temp['num'])
        total_num = sum(values)
        geos.append(Geo( str(years[index]) + " , Fist level title" , title_top = "10%" , title_text_size=50 , subtitle = "second level title" , \
            subtitle_text_size = 23 , subtitle_color="white", \
            title_color="red", title_pos="center", width=1200, height=600, \
            background_color='#404a59'))
        # type="effectScatter", is_random=True, effect_scale=5  使点具有发散性
        geos[index].add("数量", cities, values, type="effectScatter", maptype='china' , is_random=True, effect_scale=3,  is_selected = True,is_toolbox_show = True ,is_more_utils =True,\
            visual_text_color="#fff", symbol_size=10, is_label_show = True ,  legend_orient = 'left' ,is_legend_show = False, legend_top = 'bottom' , label_formatter = '{b}' , \
            is_visualmap=True, is_roam=True , label_text_color="#00FF00" , is_piecewise=True, label_text_size = 7,visual_range=[1, 300] , \
            geo_cities_coords = {'柯桥': [120.443 , 30.0822] ,}  , \
            pieces=[
                {"min":0.1, "max": 500 , "label": "0-500"},
                {"min": 500, "max": 1000 , "label": "501-1000"},
                {"min": 1001, "max": 2000 , "label": "1001-2000"},
                {"min":2001, "max": 5000, "label": "2001-5000"},
                {"min":5001, "max": 100000, "label": ">5000"}, ] )
        geos[index].show_config()
        geos[index].render("数量.html")
        #   时间轴定义
        timeline.add(geos[index], years[index])
    timeline.render('redult.html')