예제 #1
0
def get_map_data():
    data = userDs.get_country_user_data()
    total = 0
    lables = []
    sizes = []
    for k in data:
        if len(k) > 0:
            try:
                index = k.index('省')
                if index > 0:
                    lables.append(k[0:index])
            except Exception as e:
                if k == '内蒙古自治区':
                    lables.append(k[0:3])
                else:
                    lables.append(k[0:2])

                pass

        sizes.append(data[k])
        total = total + data[k]

    max = numpy.max(sizes)
    min = numpy.min(sizes)
    map = Map("共爬取%s个用户" % total, width=1200, height=600)
    map.add("全国",
            lables,
            sizes,
            maptype='china',
            visual_range=[min, max],
            is_visualmap=True,
            is_label_show=True,
            visual_text_color='#007')
    map.render('map.html')
    return send_file('map.html')
예제 #2
0
def region_distribution():

    # 使用一个字典统计好友地区分布数量
    province_dict = {
        '北京': 0,
        '上海': 0,
        '天津': 0,
        '重庆': 0,
        '河北': 0,
        '山西': 0,
        '吉林': 0,
        '辽宁': 0,
        '黑龙江': 0,
        '陕西': 0,
        '甘肃': 0,
        '青海': 0,
        '山东': 0,
        '福建': 0,
        '浙江': 0,
        '台湾': 0,
        '河南': 0,
        '湖北': 0,
        '湖南': 0,
        '江西': 0,
        '江苏': 0,
        '安徽': 0,
        '广东': 0,
        '海南': 0,
        '四川': 0,
        '贵州': 0,
        '云南': 0,
        '内蒙古': 0,
        '新疆': 0,
        '宁夏': 0,
        '广西': 0,
        '西藏': 0,
        '香港': 0,
        '澳门': 0
    }

    # 遍历
    for i in friends_dict.keys():
        # 判断省份是否存在,有可能是外国的,这种情况不考虑
        if (friends_dict[i][3] in province_dict):
            key = friends_dict[i][3]
            province_dict[key] += 1

    provice = list(province_dict.keys())
    values = list(province_dict.values())

    # maptype='china' 只显示全国直辖市和省级,数据只能是省名和直辖市的名称
    map = Map("微信好友地区分布")
    map.add("",
            provice,
            values,
            visual_range=[0, 50],
            maptype='china',
            is_visualmap=True,
            visual_text_color='#000')
    map.render(path="data/好友地区分布.html")
예제 #3
0
def analyse_location(friends):
    """
    分析好友地理位置
    :param friends:
    :return:
    """
    friend = dict(province=get_attr(friends, 'Province'),
                  city=get_attr(friends, 'City'),
                  nickname=get_attr(friends, 'NickName'))
    print('friend>>>', friend)
    province = pandas.DataFrame(friend)
    print('province>>>', province)
    provinces = province.groupby(
        'province', as_index=True)['province'].count().sort_values()
    print('provinces>>>', provinces)
    # 未填写地址的改为未知
    unknow = list(map(lambda x: x if x != '' else '未知', list(provinces.index)))
    value = list(provinces)
    _map = Map('微信好友位置分布图', title_pos='center', width=1000, height=500)
    _map.add('',
             unknow,
             value,
             is_label_show=True,
             is_visualmap=True,
             visual_text_color='#000',
             visual_range=[0, 120])
    _map.render('provinces.html')
예제 #4
0
def generate1(maptype, attr, value, folder_type, label_name):
    split_number = 5  # 分段的个数
    max_value = cal_proper_max_value(max(value), split_number)
    map = Map(maptype, width=800, height=500, title_pos="10%")
    map.add(
        "",
        attr,
        value,
        maptype=maptype,
        is_roam=True,
        is_label_show=True,
        is_map_symbol_show=False,
        is_visualmap=True,
        visual_range=[0, max_value],  # 最大值必须要大于真实的数值
        visual_text_color="#000",
        visual_range_color=['#CCFFFF', '#99CCFF', '#336699', '# 003366'],
        visual_range_text=[' ', '单位(人天数)'],
        # is_piecewise=True,  # 加上后组件为分段型
        # visual_split_number=split_number,  # 分段的个数
        tooltip_formatter=format,
        # label_formatter=label_format, #地图上省份直接显示数据
    )
    # map.use_theme("shine")
    map._option.get("toolbox").get("feature").update({
        "myTool": {
            "show": True,
            "title": "返回全国地图",
            "icon": home_icon,
            "onclick": return_home
        },
    })
    map.on(events.MOUSE_CLICK, on_click)
    # map.render("./maps" + "ggggg人天数组合图" + ".html")

    map.render("./maps/" + folder_type + "/" + maptype + '.html')
예제 #5
0
def plot_location(friends):
    ## 通过循环实现将所有好友所在省份加到列表中,并且去除空字符
    for friend in friends[1:]:
        map_province.append(friend['Province'])
        while '' in map_province:
            map_province.remove('')  # 删除空字符
    # 将上述列表通过set变为字典,去重
    map_dict = set(map_province)
    # 生成一个key为省份,value为省份出现总数的字典
    for mdi in map_dict:
        map_prodic[mdi] = map_province.count(mdi)
    print(map_prodic)
    # 通过循环将上述的字典拆分为两个列表,分别围殴map_attr,map_val,用于下面pyecharts绘制图形
    for province_key in map_prodic:
        map_attr.append(province_key)
        map_val.append(map_prodic[province_key])
    print(map_attr)
    print(map_val)
    # 开始绘制
    map = Map(my["NickName"] + "的微信好友位置分布图",
              width=1200,
              height=600,
              title_pos='center')
    map.add("",
            map_attr,
            map_val,
            is_visualmap=True,
            visual_range=[0, 120],
            visual_text_color='#000',
            is_map_symbol_show=False,
            is_label_show=True)
    map.render()
예제 #6
0
def test_world_map():
    value = [95.1, 23.2, 43.3, 66.4, 88.5, 0.1]
    attr = [
        "China",
        "Canada",
        "Brazil",
        "Russia",
        "United States",
        "Unknown Country",
    ]
    map = Map("世界地图示例", width=1200, height=600)
    map.add(
        "",
        attr,
        value,
        maptype="world",
        is_visualmap=True,
        visual_text_color="#000",
    )
    map.render()

    actual_content = get_default_rendering_file_content()
    # test register map
    assert 'registerMap("world",' in actual_content
    # test non-existent country
    assert "Russia" in actual_content
    assert "Unknown Country', " not in actual_content
예제 #7
0
def r_data(file):
    province_c = []
    csv_file = open(file)  # 打开csv文件
    csv_reader_lines = csv.reader(csv_file)  # 逐行读取csv文件
    for one_line in csv_reader_lines:
        # print(one_line)
        province_c.append(one_line)
    # print(province_c)

    for i in province_c[1:]:
        province.append(i[0].replace("省", "").replace("自治区", "").replace(
            "壮族", "").replace("回族", "").replace("维吾尔", ""))
        values.append(i[1])
        print(i)

    map = Map("医院数量地区分布图", '2020年', width=1500, height=750)
    map.add("",
            province,
            values,
            visual_range=[0, 10],
            maptype='china',
            is_visualmap=True,
            visual_text_color='#000',
            is_map_symbol_show=False,
            is_label_show=True)
    map.render(path="data/wjp.html")
예제 #8
0
    def visualRiskHeat(self):
    
        print('It may take some time. Thank you for your patience.') # print for long waiting time
    
        Countries = ['United States','Brazil','India','Russia','Spain','Japan','Greece','Australia','France',
                     'Singapore','Germany','Egypt','Korea','South Africa','Mexico','Peru','Chile','United Kingdom']

        SIRengine = SIR()

        risks = []

        try:
            for i in Databook.COUNTRY_TS.keys():

                SIRengine.loadData(CrawlByYinjie(Databook.COUNTRY_TS[i]).getData())
                risks.append(SIRengine.R0)
        except:
                self.ConnectException()

        mapEco = Map('World Future Risks of COVID-19 based on R0', width=1000, height=800)
        mapEco.add('World Map', Countries, risks,
                         visual_range=[min(risks), max(risks)],
                         maptype="world", is_visualmap=True, geo_normal_color='808080',visual_text_color='#000')
        mapEco.render(path="World_Risk.html")
    
    
        webbrowser.open('file://' + os.getcwd() + '/World_Risk.html')
예제 #9
0
    def view_block_area_map(self):
        """
        需要的数据
        self.data_list
            [(province, value), (province, value)]
        :return:
        """
        print("开始生成 %s年 全国%s 销货汇总热力图" % (self.start_year, self.table_name))
        c_map = Map("全国%s 销货汇总热力图" % self.table_name,
                    "%s年" % self.start_year,
                    width=1200,
                    height=600,
                    page_title="Map")
        pro = [province for province, _ in self.data_list]
        val = [value for _, value in self.data_list]

        c_map.add("",
                  pro,
                  val,
                  maptype='china',
                  is_visualmap=True,
                  visual_range=[min(val), max(val)],
                  visual_text_color="#fff",
                  symbol_size=15,
                  is_toolbox_show=False)
        c_map.render(
            path=self.BASE_PATH +
            "{}{}_sales_hot_area.html".format(self.start_year, self.html_name))
예제 #10
0
def show_lends(r):
	names=r.keys()
	nums=r.values
	map = Map("主要来源城市", width=1200, height=600,title_color="#fff", title_pos="center")
	map.add("", attr, value, maptype='广东', is_visualmap=True, visual_text_color='#000')
	map.show_config()
	map.render()
예제 #11
0
def draw_map(word):
    results = [('50.53.1.33', 'United States'), ('27.7.33.30', 'India'), ('8.37.96.36', 'United States'), ('50.109.75.78', 'United States'), ('90.221.222.69', 'United Kingdom'), ('37.39.199.13', 'Kuwait'), ('119.235.50.170', 'India'), ('37.106.181.109', 'Saudi Arabia'), ('134.193.238.227', 'United States'), ('2405:204:1389:e5c2:8c1c:39fc:8605:a898', 'India'), ('41.239.21.3', 'Egypt'), ('192.54.144.229', 'France'), ('68.57.254.129', 'United States'), ('216.80.103.176', 'United States'), ('49.205.216.210', 'India'), ('62.255.128.67', 'United Kingdom'), ('111.92.46.179', 'India'), ('2.218.17.222', 'United Kingdom'), ('117.224.233.3', 'India'), ('1.22.102.23', 'India'), ('183.82.37.234', 'India'), ('2602:306:3796:abd0:bc72:1033:4871:7dd1', 'United States'), ('2405:204:d087:d48e:d4ba:1788:612f:977c', 'India'), ('85.86.231.102', 'Spain'), ('77.131.79.194', 'France'), ('46.188.158.93', 'Croatia'), ('27.154.219.75', 'China'), ('220.227.205.189', 'India'), ('2003:c3:5f14:4d00:adf2:9703:2ef2:a770', 'Germany'), ('85.193.242.133', 'Poland'), ('70.184.214.35', 'United States'), ('24.142.209.86', 'United States'), ('73.162.65.52', 'United States'), ('70.24.205.94', 'Canada'), ('103.15.62.18', 'India'), ('76.14.39.29', 'United States'), ('134.193.69.220', 'United States'), ('85.56.120.25', 'Spain'), ('71.242.244.146', 'United States'), ('112.134.39.136', 'Sri Lanka'), ('2600:8800:7b01:880:7850:da8d:4342:7bc6', 'United States'), ('62.203.35.109', 'Switzerland'), ('141.131.2.3', 'United States'), ('114.29.237.80', 'India'), ('108.179.38.243', 'United States'), ('2601:183:847f:e15b:f841:b4fd:f8bc:e57', 'United States'), ('27.106.92.189', 'India'), ('106.51.26.242', 'India'), ('131.152.137.48', 'Switzerland'), ('98.65.194.191', 'United States'), ('187.189.102.199', 'Mexico'), ('176.51.204.190', 'Russia'), ('81.247.46.88', 'Belgium'), ('154.122.62.116', 'Kenya'), ('105.151.170.37', 'Morocco'), ('188.23.105.235', 'Austria'), ('81.106.240.17', 'United Kingdom'), ('2600:100d:b00d:9e44:2165:cd79:1ed3:7d18', 'United States'), ('115.114.50.215', 'India'), ('213.97.248.159', 'Spain'), ('85.92.160.163', 'United Kingdom'), ('2001:630:212:de0:583e:6fad:64ad:886a', 'United Kingdom'), ('130.92.255.36', 'Switzerland'), ('47.8.142.195', 'India'), ('78.48.131.210', 'Germany'), ('95.172.232.240', 'United Kingdom'), ('50.53.1.21', 'United States'), ('203.163.252.26', 'India'), ('220.94.163.15', 'Republic of Korea'), ('85.255.237.147', 'United Kingdom'), ('160.127.15.38', 'United States'), ('103.16.71.19', 'India'), ('87.66.197.101', 'Belgium'), ('192.140.221.149', 'India'), ('2001:5b0:4ec5:4608:d982:b293:4e60:af15', 'United States'), ('187.189.246.28', 'Mexico'), ('77.65.100.186', 'Poland'), ('182.65.122.82', 'India'), ('80.249.56.118', 'United Kingdom'), ('61.12.45.214', 'India'), ('122.172.173.70', 'India'), ('150.107.25.212', 'India'), ('85.95.189.104', 'Russia'), ('12.156.20.2', 'United States'), ('81.136.225.91', 'United Kingdom'), ('2a00:23c5:6e09:c400:3547:6914:5b6:cb5a', 'United Kingdom'), ('175.136.38.52', 'Malaysia'), ('210.212.247.38', 'India'), ('183.83.82.2', 'India'), ('103.21.77.58', 'India'), ('213.168.107.162', 'Germany'), ('195.194.86.66', 'United Kingdom'), ('86.120.91.155', 'Romania'), ('103.241.244.36', 'India'), ('180.190.43.58', 'Philippines'), ('199.172.169.86', 'United States'), ('31.147.240.138', 'Croatia'), ('182.72.162.3', 'India'), ('146.163.156.200', 'United States'), ('24.80.84.36', 'Canada'), ('77.178.142.167', 'Germany'), ('140.193.113.207', 'Canada'), ('202.153.45.19', 'India')]
    with open(word+".csv", 'w', encoding='utf-8') as f:
        for i in results:
            f.write(str(i[0]))
            f.write(",")
            f.write(str(i[1])+'\n')
    f.close()
    names = []
    values = []
    countrys = [i[1] for i in results]
    stats = collections.Counter(countrys)

    datas = sorted(dict(stats).items(), key=lambda x: x[1], reverse=True)

    with open(word+"_order.csv", 'w', encoding='utf-8') as f:
        for i in datas:
            f.write(str(i[0]))
            f.write(",")
            f.write(str(i[1])+'\n')
    f.close()

    for each in datas:
        names.append(each[0])
        values.append(each[1])
    word_map = Map("维基词条: "+word+" 各国编辑量统计", width=800, height=400)
    word_map.add("", names, values, maptype="world", is_visualmap=True,
                 is_piecewise=True, visual_text_color='#000', is_map_symbol_show=False,
                 pieces=[{"min": 25, "label": ">25"}, {"max": 25, "min": 15, "label": "15-25"}, {"max": 15, "min": 5, "label": "5-15"},
                        {"max": 5, "min": 2, "label": "2-5"},{"max": 1, "min": 0, "label": "<2"}], is_more_utils=True)
    file_name = word+"_chart.html"  # svg/png/pdf等都支持,具体可看官方文档
    word_map.render(file_name)
예제 #12
0
def test_world_map():
    value = [95.1, 23.2, 43.3, 66.4, 88.5, 0.1]
    attr = [
        "China",
        "Canada",
        "Brazil",
        "Russia",
        "United States",
        "Unknown Country",
    ]
    map = Map("世界地图示例", width=1200, height=600)
    map.add(
        "",
        attr,
        value,
        maptype="world",
        is_visualmap=True,
        visual_text_color='#000',
    )
    map.render()

    actual_content = get_default_rendering_file_content()
    # test register map
    assert "registerMap(\"world\"," in actual_content
    # test non-existent country
    assert "Russia" in actual_content
    assert "Unknown Country', " not in actual_content
예제 #13
0
def generate_map():
    data = get_city_data('friend.json')
    map = Map(
        "微信好友",
        "热力图",
        title_color="#fff",
        title_pos="center",
        width=600,
        height=500,
        background_color="#404a59",
    )
    # geo.use_theme('dark')
    attr, value = map.cast(data)
    map.add(
        "",
        attr,
        value,
        maptype="china",
        visual_range=[0, 200],
        visual_text_color="#fff",
        symbol_size=15,
        is_visualmap=True,
        # is_label_show=True
    )

    map.render('map.html')
    map.render(path='map.png')
예제 #14
0
def show():
    selectsql = "SELECT distr_name,distr_num FROM whdistricts;"
    cur.execute(selectsql.encode('utf-8'))

    house = list(cur.fetchall())
    """
    data = [
    ("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15),
    ("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21),
    ("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25)]
    """
    hou = []
    hou += house[1:8] + house[9:]

    attr = [i[0] for i in hou]

    value = [j[1] for j in hou]
    m = max(value)
    for i in range(len(attr)):
        if attr[i][-1] != "区":
            attr[i] += "区"
    # # 商丘地图 数据为商丘市下的区县
    map3 = Map("武汉市房源数量分布图", '武汉', width=1200, height=600)
    map3.add("武汉",
             attr,
             value,
             visual_range=[0, m + 1],
             maptype='武汉',
             is_visualmap=True,
             visual_text_color='#000')
    map3.render(path="./房源数量热力图.html")
예제 #15
0
    def analysis_address(self):
        """所有类型企业的位置可视化"""
        address = []
        filed = []
        attr = []
        counter = Counter()
        for collection in self.collection:
            cursor = collection.find({}, {"Address1": 1, "_id": 0})
            for item in cursor:
                address.append(
                    item.get('Address1')[1].replace("市", '').replace("省", ''))
        for Address in address:
            counter[Address] += 1

        for k, v in counter.most_common(100):
            filed.append(k)
            attr.append(v)

        map = Map("36kr创投企业省级分布图", width=1200, height=600)
        map.add(
            "",
            filed,
            attr,
            maptype="china",
            is_visualmap=True,
            visual_text_color="#000",
            is_map_symbol_show=False,
        )

        map.render("Address.html")
예제 #16
0
def test_map_show_label():
    # show label
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='china', is_label_show=True)
    map.render()
예제 #17
0
def test_map_show_label():
    # show label
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='china', is_label_show=True)
    map.render()
    def location(self):
        """分析发布微博信息含有“晚安”的用户的所在省级单位,并且数据可视化"""
        cursor = self.collection.find({}, {"location": 1, "" "_id": 0})
        # 去掉 地区="其他" 和 "None"
        location = [
            location.get('location') for location in cursor
            if location.get('location') != "其他" and location.get('location')
        ]
        # 去掉 海外用户
        location = [loc for loc in location if "海外" not in loc]
        # 获取省、直辖市
        location = [loc.split()[0] for loc in location if " " in loc]

        filed, attr = [], []
        counter = Counter()
        for loc in location:
            counter[loc] += 1
        for k, v in counter.most_common():
            filed.append(k)
            attr.append(str(int(v) / 10))

        map = Map("", width=1200, height=600)
        map.add(
            "",
            filed,
            attr,
            maptype="china",
            is_visualmap=True,
            visual_text_color="#000",
            is_map_symbol_show=False,
        )

        map.render("location.html")
예제 #19
0
def drawCountOfDifferentCountry(attr, value):
    #    data = pd.read_csv('directory.csv')
    #    data_jingwei = data.values[:,11:].tolist()
    #    data_name = data.values[:,2].tolist()
    #    weizhi = dict(zip(data_name,data_jingwei))
    #    attr = data_name
    #    value1 = data.values[:,7].tolist()
    #    dict1 = Counter(value1)
    #    attr =['Andorra', 'United Arab Emirates', 'Argentina', 'Austria', 'Australia', 'Aruba', 'Azerbaijan', 'Belgium', 'Bulgaria', 'Bahrain', 'Brunei', 'Bolivia', 'Brazil', 'Bahamas', 'Canada', 'Switzerland', 'Chile', 'China', 'Colombia', 'Costa Rica', 'Cornwall', 'Cyprus', 'Czech Republic', 'Germany', 'Denmark', 'Egypt', 'Spain', 'Finland', 'France', 'United Kiongdom', 'Greece', 'Guatemala', 'Hungary', 'Indonesia', 'Ireland', 'India', 'Jordan', 'Japan', 'Cambodia', 'Korea', '	Kuwait', 'Kazakstan', 'Lebanon', 'Luxembourg', 'Morocco', 'Monaco', 'Mexico', 'Malaysia', 'Netherlands', 'Norway', 'New Zealand', 'Oman', 'Panama', 'Peru', 'Philippines', 'Poland', 'Puerto Rico', 'Portugal', 'Qatar', 'Romania', 'Russia', 'Saudi Arabia', 'Sweden', 'Singapore', 'Slovakia', 'EI Salvador', 'Thailand', 'Turkey', 'Trinidad and Tobago', 'Taiwan', 'United States', 'Vietnam', 'South Africa']
    #    value = dict1.values()
    map = Map("星巴克在各个国家的分布密度",
              "颜色越深代表分布的密度越大",
              width=1200,
              height=600,
              title_pos='center')
    map.add("",
            attr,
            value,
            visual_range=[1, 300],
            type="heatmap",
            maptype="world",
            is_visualmap=True,
            visual_text_color='#000',
            is_map_symbol_show=True)
    map.render("drawCountOfDifferentCountry.html")
예제 #20
0
    def place1(self):
        attr = [
            '安徽', '北京', '福建', '广东', '贵州', '海南', '河北', '河南', '黑龙江', '湖北', '湖南',
            '吉林', '江苏', '辽宁', '山东', '山西', '陕西', '上海', '四川', '天津', '云南', '浙江',
            '重庆'
        ]
        friend = []  # 好友所在的省份
        for i in self.friends[1:]:
            friend.append(i['Province'])
        print(friend)
        location = collections.Counter(friend)  # 一个迭代对象生成的counter

        value = []  # weixin1 Map
        for i in attr:  # value 每个省会对应的数量
            value.append(location[i])
        print(value)
        map = Map(u"%s的 各省微信好友分布" % self.nickName,
                  "冀祥",
                  width=1200,
                  height=600)
        map.add("",
                attr,
                value,
                maptype='china',
                is_visualmap=True,
                visual_text_color='#000')
        # map.show_config()
        map.render('%s的好友分部图1.html')
예제 #21
0
def DrawMap(title, data, savepath='./results'):
	if not os.path.exists(savepath):
		os.mkdir(savepath)
	map_ = Map(title, width=1200, height=600)
	attrs = [i for i, j in data.items()]
	values = [j for i, j in data.items()]
	map_.add('', attrs, values, maptype='china', is_visualmap=True, visual_text_color='#000')
	map_.render(os.path.join(savepath, '%s.html' % title))
예제 #22
0
def test_map_combine_with_visualmap():
    value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]
    attr = ["福建", "山东", "北京", "上海", "甘肃",
            "新疆", "河南", "广西", "西藏"]
    map = Map("Map 结合 VisualMap 示例", width=1200, height=600)
    map.add("", attr, value, maptype='china', is_visualmap=True,
            visual_text_color='#000')
    map.render()
예제 #23
0
def get_map(item_name,item_name_list,item_num_list):
    subtitle = "微信公众号:大数据前沿"
    _map = Map(item_name,width=1300,height= 800,title_pos='center',title_text_size=30,\
        subtitle = subtitle,subtitle_text_size = 25)
    _map.add("", item_name_list, item_num_list, maptype='china', is_visualmap=True, visual_text_color='#000')

    out_file_name = './analyse/'+item_name+'.html'
    _map.render(out_file_name)
def test_map_show_label():
    # show label
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype="china", is_label_show=True)
    map.on(events.MOUSE_CLICK, on_click)
    map.render("click_map.html")
예제 #25
0
def map_demo1():
    from pyecharts import Map
    districts = ['常平', '大朗','寮步', '厚街']
    areas = [10, 20, 3, 11]
    map_1 = Map("东莞市图例-各区面积", width=1200, height=600)
    map_1.add("", districts, areas, maptype='东莞', is_visualmap=True, visual_range=[min(areas), max(areas)],
              visual_text_color='#000', is_map_symbol_show=False, is_label_show=True)
    map_1.render('map.html')
예제 #26
0
파일: analyse.py 프로젝트: lbio233/wechat
def get_map(item_name,item_name_list,item_num_list):
    subtitle = "lbio_wechat"
    _map = Map(item_name,width=1300,height= 800,title_pos='center',title_text_size=30,\
        subtitle = subtitle,subtitle_text_size = 25)
    _map.add("", item_name_list, item_num_list, maptype='china', is_visualmap=True, visual_text_color='#000',is_label_show=True)

    out_file_name = './analyse/'+item_name+'.html'
    _map.render(out_file_name)
예제 #27
0
def fenxi():
    # 读取数据库中的数据
    curr = pymongo.MongoClient()
    database = curr["renren"]
    coll = database['friends']
    friends_list_all_find = coll.find({})
    friends_list_all = []
    for f in friends_list_all_find:
        friends_list_all.append(f)
    curr.close()

    # 统计省份信息
    result = {}
    for f in friends_list_all:
        if f["province"] not in result.keys():
            result[f["province"]] = 1
        else:
            result[f["province"]] += 1

    # 对统计数据进行过滤,去除没有省份的数据和小于100的数据
    result_gt100 = {}
    for k, v in result.items():
        if v >= 100:
            if k.strip():
                result_gt100[k] = v

    # 对数据按照省份值进行排序
    result_gt100_sorted = sorted(result_gt100.items(),
                                 key=lambda x: x[1],
                                 reverse=True)

    # 统计出key列表和value列表,下面生成统计图使用
    key = []
    value = []
    for k in result_gt100_sorted:
        key.append(k[0])
        value.append(k[1])
    # 柱形图
    bar = Bar("柱状图", width=2000, height=1000)
    bar.add("", key, value, is_label_show=True)
    bar.render(path="柱状图.html")

    # 全国地图
    map = Map("全国地图示例", width=2000, height=1000)
    map.add("",
            key,
            value,
            maptype='china',
            is_visualmap=True,
            visual_text_color="#000",
            is_map_symbol_show=False,
            visual_range=[0, 1000])
    map.render(path="地图.html")

    # 词云图
    wordcloud = WordCloud(width=2000, height=1000)
    wordcloud.add("", key, value, word_size_range=[50, 250])
    wordcloud.render(path="词云.html")
예제 #28
0
def world_map():
    # maptype='world' 显示世界各个国家(英文名)
    # 世界地图数据
    value = [95.1, 23.2, 43.3, 66.4, 88.5]
    attr = ["China", "Canada", "Brazil", "Russia", "United States"]

    map0 = Map(title="世界地图示例", subtitle='world map', width=1200, height=600, page_title='wdf-map')
    map0.add("世界地图", attr, value, maptype="world", is_visualmap=True, visual_text_color='#000')
    map0.render(path="./data/世界地图.html")
예제 #29
0
 def draw_county_map(self):
     maps = Map("湘乡地图", '', width=1200, height=600)
     maps.add("湘乡",
              self.list_city_name,
              self.list_city_num,
              maptype='娄底市',
              is_visualmap=True,
              visual_text_color='#000')
     maps.render(self.location)
예제 #30
0
 def draw_province_map(self):
     maps = Map("湖南省地图", '湖南', width=1200, height=600)
     maps.add('湖南',
              self.list_city_name,
              self.list_city_num,
              maptype='湖南',
              is_visualmap=True,
              visual_text_color='#000')
     maps.render(self.location)
예제 #31
0
파일: ta.py 프로젝트: piaoxue85/wakuang
def draw_area_map():
    df=stock_info.read_stock_inoformation_csv()
    map_values= df.area.value_counts()
    
    map_=Map("stock",width=1200, height=600)
    map_.add("",map_values.index,map_values.values , maptype='china',is_visualmap=True,visual_text_color='#000')
    map_.on(events.MOUSE_CLICK, on_click)
             
    map_.render()
예제 #32
0
def chartMap():

    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='china')
    map.render(path)

    pass
예제 #33
0
 def draw_world_map(self):
     maps = Map("世界地图", title_pos="center", width=1200, height=600)
     maps.add("",
              self.list_city_name,
              self.list_city_num,
              maptype="world",
              is_visualmap=True,
              visual_text_color='#000')
     maps.render(self.location)
예제 #34
0
def get_map(graph_tittle, name_list, value_list):
    map = Map(title=graph_tittle)
    map.add("",
            name_list,
            value_list,
            is_visualmap=True,
            visual_text_color="#000")
    file_name = graph_tittle + ".html"
    map.render(file_name)
예제 #35
0
    def generatemap(self):

        # 制作地图,关于一点点在广州各个区的分布,先建立列表,根据每个区
        map = Map('一点点在广州市的分布', width=1200, height=1000)
        map.add('一点点在广州市的分布', self.areas, self.value, maptype='广州', visual_range=[min(self.value), max(self.value)],
                is_map_symbol_show=False,
                is_label_show=True, is_visualmap=True, label_text_color='#509')
        # map.show_config()
        map.render('一点点在广州市的分布.html')
예제 #36
0
def test_map_show_label():
    # show label
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype="china", is_label_show=True)
    map.on(events.MOUSE_CLICK, on_click)
    map.render()
    content = get_default_rendering_file_content()
    assert "function on_click(params) {" in content
    assert '("click", on_click);' in content
예제 #37
0
def test_echarts_position_in_render_html():
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='广东', is_map_symbol_show=False,
            is_visualmap=True, visual_text_color='#000')
    map.render()
    with codecs.open('render.html', 'r', 'utf-8') as f:
        actual_content = f.read()
        echarts_position = actual_content.find('exports.echarts')
        guangdong_position = actual_content.find(json.dumps('广东'))
        assert echarts_position < guangdong_position
        assert '"showLegendSymbol": false' in actual_content
예제 #38
0
def test_china_map():
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype="china")
    map.render()

    actual_content = get_default_rendering_file_content()
    # test register map
    assert 'registerMap("china",' in actual_content
    # 福建省
    assert "\u798f\u5efa" in actual_content
    # 汕头市
    assert "\u4e0a\u6d77" in actual_content
예제 #39
0
def test_china_map():
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='china')
    map.render()

    with codecs.open('render.html', 'r', 'utf-8') as f:
        actual_content = f.read()
        # test register map
        assert "registerMap(\"china\"," in actual_content
        # 福建省
        assert "\u798f\u5efa" in actual_content
        # 汕头市
        assert "\u4e0a\u6d77" in actual_content
예제 #40
0
def test_echarts_position_in_render_html():
    value = [20, 190, 253, 77, 65]
    attr = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市"]
    map = Map("广东地图示例", width=1200, height=600, page_title=TITLE)
    map.add(
        "",
        attr,
        value,
        maptype="广东",
        is_visualmap=True,
        visual_text_color="#000",
    )
    map.render()
    actual_content = get_default_rendering_file_content()
    assert TITLE in actual_content
예제 #41
0
def test_map_with_custom_name_map():
    # show label
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add(
        "",
        attr,
        value,
        maptype="china",
        is_label_show=True,
        name_map={"test": "--magic--"},
    )
    map.render()
    content = get_default_rendering_file_content()
    assert "--magic--" in content
    assert "nameMap" in content
예제 #42
0
def test_world_map():
    value = [95.1, 23.2, 43.3, 66.4, 88.5, 0.1]
    attr = [
        "China", "Canada", "Brazil", "Russia",
        "United States", "Unknown Country"
    ]
    map = Map("世界地图示例", width=1200, height=600)
    map.add("", attr, value, maptype="world", is_visualmap=True,
            visual_text_color='#000')
    map.render()

    with codecs.open('render.html', 'r', 'utf-8') as f:
        actual_content = f.read()
        # test register map
        assert "registerMap(\"world\"," in actual_content
        # test non-existent country
        assert "Russia" in actual_content
        assert "Unknown Country', " not in actual_content
예제 #43
0
def test_echarts_position_in_render_html():
    value = [20, 190, 253, 77, 65]
    attr = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市"]
    map = Map("广东地图示例", width=1200, height=600)
    map.add(
        "",
        attr,
        value,
        maptype="广东",
        is_map_symbol_show=False,
        is_visualmap=True,
        visual_text_color="#000",
    )
    map.render()
    content = get_default_rendering_file_content()
    echarts_position = content.find("exports.echarts")
    guangdong_position = content.find(json.dumps("广东"))
    assert echarts_position < guangdong_position
    assert '"showLegendSymbol": false' in content
예제 #44
0
def test_map():

    # map_0
    value = [155, 10, 66, 78]
    attr = ["福建", "山东", "北京", "上海"]
    map = Map("全国地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='china')
    map.show_config()
    map.render()

    # map_1
    value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]
    attr = ["福建", "山东", "北京", "上海", "甘肃", "新疆", "河南", "广西", "西藏"]
    map = Map("Map 结合 VisualMap 示例", width=1200, height=600)
    map.add("", attr, value, maptype='china', is_visualmap=True, visual_text_color='#000')
    map.show_config()
    map.render()

    # # map_2
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='广东', is_visualmap=True, visual_text_color='#000')
    map.show_config()
    map.render()
예제 #45
0
    def draw_result(self):
        mongo_region_dist = mongo_db['regiondist']
        regiondist = mongo_region_dist.find({}, {"_id": 0})
        attr = []
        value = []
        for item in regiondist:
            value.append(item['totalCount'])
            attr.append(item["region"])
        map = Map("淘宝淘女郎全国分布图", width=1200, height=600)
        map.add("", attr, value, maptype='china', visual_range=[0, 5000], is_visualmap=True,
                         visual_text_color='#000')
        map.render(r"charts/regionDistribute.html")

        #某些城市的地理坐标无法正确获取,故绘图结果不不正确,待完善
        '''mongo_city_dist = mongo_db['citydist']
        citydist = mongo_city_dist.find({}, {"_id": 0})
        attr = []
        value = []
        for item in citydist:
            value.append(item['totalCount'])
            attr.append(item["city"])
        geo = Geo("淘宝淘女郎城市分布图", "data from mm.taobao.com", title_color="#fff", title_pos="center",
                  width=1200, height=600, background_color='#404a59')
        geo.add("", attr, value, visual_range=[0, 1000], visual_text_color="#fff", symbol_size=12, is_visualmap=True)
        geo.render(r"charts/cityDistribute.html")'''

        mongo_height_stat = mongo_db['heightstat']
        heightstat = mongo_height_stat.find({}, {"_id": 0})
        attr = []
        value = []
        for item in heightstat:
            value.append(item['value'])
            attr.append(item["height"])
        bar = Bar("淘宝淘女郎身高分布图", "data from mm.taobao.com")
        bar.add("", attr,value)
        bar.render("charts/heightstat.html")

        mongo_weight_stat = mongo_db['weightstat']
        weightstat = mongo_weight_stat.find({}, {"_id": 0})
        attr = []
        value = []
        for item in weightstat:
            value.append(item['value'])
            attr.append(item["weight"])
        bar = Bar("淘宝淘女郎体重分布图", "data from mm.taobao.com")
        bar.add("", attr, value)
        bar.render("charts/weightstat.html")

        mongo_blood_stat = mongo_db['bloodstat']
        bloodstat = mongo_blood_stat.find({}, {"_id": 0})
        attr = []
        value = []
        for item in bloodstat:
            value.append(item['value'])
            attr.append(item["blood"])
        bar = Bar("淘宝淘女郎血型分布图", "data from mm.taobao.com")
        bar.add("", attr, value)
        bar.render("charts/bloodstat.html")

        mongo_birthday_stat = mongo_db['birthdaystat']
        birthdaystat = mongo_birthday_stat.find({}, {"_id": 0})
        attr = []
        value = []
        for item in birthdaystat:
            value.append(item['value'])
            attr.append(item["blood"])
        bar = Bar("淘宝淘女郎生日星座分布图", "data from mm.taobao.com")
        bar.add("", attr, value)
        bar.render("charts/birthdaystat.html")
예제 #46
0
data['单价']=data['价格']/data['面积']
data['单价'][data['单价']>0.3].plot.hist(bins = 20,title='在售二手房单价直方图',figsize = (12, 9))
a=data[['单价','区']].dropna()

grouped =a['单价'].groupby(a['区']).apply(np.median)
a=list(grouped.index[0:2]+'区')
a.append('亦庄开发区')
a=a+list(grouped.index[3:]+'区')
grouped.index=a
from pyecharts import Map
value =list(grouped)
attr =list(grouped.index)
map=Map("二手房在售单价中位数 单位:万元", width=1200, height=600)
map.add("", attr, value, maptype='北京', is_visualmap=True, visual_text_color='#404a59',visual_range=[1,10],is_map_symbol_show =False)
map.show_config()
map.render()

df=pd.read_csv('ershoufangshuju.csv',encoding='gbk')
del df['Unnamed: 0']
df['电梯'][df['类型']=='有电梯']=df['类型'][df['类型']=='有电梯']
df['电梯'][df['类型']=='无电梯']=df['类型'][df['类型']=='无电梯']
df['类型'][df['类型']=='有电梯']=np.NaN
df['类型'][df['类型']=='无电梯']=np.NaN

tmp=pd.crosstab(df['区'],df['类型'],margins=True)
def plotbar_Stacked(tmp,t=''):
    tmp=tmp.apply(lambda x:x/x[-1],axis=1)
    tmp=tmp.drop('All',1).drop('All',0)
    tmp.plot.bar(stacked=True,figsize = (12, 9),title=str(t))
plotbar_Stacked(tmp,'各区在售二手房装修类型比重')
df['室数']=df['户型']
예제 #47
0
population = [1376048943, 35939927, 1311050527, 143456918, 321773631,126573481]
life_expectancy = [76.9,81.7,66.8,73.13,79.1,73.13]

m = Map("世界经济发展水平", width=1024, height=576)
m.add(
    "人均GDP",
    attr = countries,
    value = capita_gdp,
    maptype="world",
    is_visualmap=True,
    visual_range = [5000,60000],
    visual_text_color="#000",
    is_map_symbol_show=False,
    visual_orient="horizontal"
)
m.render('result.地理坐标系图.世界地图示例.html')

#  全国省份地图
from pyecharts import Map
value = [155, 10, 66, 78, 44, 38, 88, 50, 20]
attr = ["福建","山东","北京","上海","江西","新疆","内蒙古","云南","重庆"]
m = Map("全国省份地图", width=600, height=400)
m.add("", attr, value, maptype='china',
        is_visualmap=True, 
        is_piecewise=True,
        visual_text_color="#000",
        visual_range_text=["", ""],
        pieces=[
            {"max": 160, "min": 81, "label": "高"},
            {"max": 80, "min": 51, "label": "中"},
            {"max": 50, "min": 0, "label": "低"},