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
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())
def draw_city_geo(data): geo = Geo("全国妹子分布城市", "data about beauty", title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') attr, value = geo.cast(data) geo.add("", attr, value, visual_range=[10, 2500], visual_text_color="#fff", symbol_size=15, is_visualmap=True) return geo
def my_personal(): data=[('东莞',10),('深圳',20)] geo = Geo("全国主要城市空气质量", "data from pm2.5", 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, 200], maptype='china', visual_text_color="#fff", symbol_size=10, is_visualmap=True) geo.render("test.html") # 生成html文件
def test_geo_with_noexist_city(): 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, effect_scale=5) geo.render()
def test_geo_china_effectscatter(): 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, effect_scale=5) assert '"type": "effectScatter"' in geo._repr_html_()
def test_geo_shantou_city(): data = [ ('澄海区', 30), ('南澳县', 40), ('龙湖区', 50), ('金平区', 60) ] geo = Geo("汕头市地图示例", **style.init_style) attr, value = geo.cast(data) geo.add("", attr, value, maptype="汕头", is_visualmap=True, tooltip_formatter='{b}', is_legend_show=False, label_emphasis_textsize=15, label_emphasis_pos='right') geo.render()
def demo2(): from pyecharts import Geo data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)] 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, type="effectScatter", is_random=True, effect_scale=5) geo.show_config() geo.render()
def test_geo_guangdong_province(): data = [ ('汕头市', 50), ('汕尾市', 60), ('揭阳市', 35), ('阳江市', 44), ('肇庆市', 72) ] geo = Geo("广东城市空气质量", "data from pm2.5", **style.init_style) attr, value = geo.cast(data) geo.add("", attr, value, maptype='广东', type="effectScatter", is_random=True, effect_scale=5, is_legend_show=False) geo.render()
def demo1(): data = [ ("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15), ("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21), ("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25)] 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, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True) geo.show_config() geo.render()
def test_geo_user_define_coords(): coords = { "0": [0.572430556, 19.246], "1": [0.479039352, 1.863], "2": [0.754143519, -20.579] } geo = Geo(**style.init_style) geo.add("", ["0", "1", "2"], [6, 5.8, 6.2], is_visualmap=True, geo_cities_coords=coords, maptype="world") geo.render()
def test_geo_china_scatter(): geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style) 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') html_content = geo._repr_html_() assert '"type": "scatter"' in html_content assert '"type": "heatmap"' not in html_content assert '"type": "effectScatter"' not in html_content
def test_geo_china_heatmap(): geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style) attr, value = geo.cast(cities) geo.add( "", attr, value, type="heatmap", is_visualmap=True, visual_range=[0, 300], visual_text_color="#fff", ) assert '"type": "heatmap"' in geo._repr_html_()
def test_geo_guangdong_province(): data = [("汕头市", 50), ("汕尾市", 60), ("揭阳市", 35), ("阳江市", 44), ("肇庆市", 72)] geo = Geo("广东城市空气质量", "data from pm2.5", **style.init_style) attr, value = geo.cast(data) geo.add( "", attr, value, maptype="广东", type="effectScatter", is_random=True, effect_scale=5, is_legend_show=False, ) geo.render()
def test_geo_shantou_city(): data = [("澄海区", 30), ("南澳县", 40), ("龙湖区", 50), ("金平区", 60)] geo = Geo("汕头市地图示例", **style.init_style) attr, value = geo.cast(data) geo.add( "", attr, value, maptype="汕头", is_visualmap=True, tooltip_formatter="{b}", is_legend_show=False, label_emphasis_textsize=15, label_emphasis_pos="right", ) geo.render()
def demo3(): from pyecharts import Geo data = [ ("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15), ("赤峰", 16), ("青岛", 18), ("乳山", 18), ("金昌", 19), ("泉州", 21), ("莱西", 21), ("日照", 21), ("胶南", 22), ("南通", 23), ("拉萨", 24), ("云浮", 24), ("梅州", 25), ("文登", 25), ("上海", 25), ("攀枝花", 25), ("威海", 25), ("承德", 25), ("厦门", 26), ("汕尾", 26), ("潮州", 26), ("丹东", 27), ("太仓", 27), ("曲靖", 27), ("烟台", 28), ("福州", 29), ("瓦房店", 30), ("即墨", 30), ("抚顺", 31), ("玉溪", 31), ("张家口", 31), ("阳泉", 31), ("莱州", 32), ("湖州", 32), ("汕头", 32), ("昆山", 33), ("宁波", 33), ("湛江", 33), ("揭阳", 34), ("荣成", 34), ("连云港", 35), ("葫芦岛", 35), ("常熟", 36), ("东莞", 36), ("河源", 36), ("淮安", 36), ("泰州", 36), ("南宁", 37), ("营口", 37), ("惠州", 37), ("江阴", 37), ("蓬莱", 37), ("韶关", 38), ("嘉峪关", 38), ("广州", 38), ("延安", 38), ("太原", 39), ("清远", 39), ("中山", 39), ("昆明", 39), ("寿光", 40), ("盘锦", 40), ("长治", 41), ("深圳", 41), ("珠海", 42), ("宿迁", 43), ("咸阳", 43), ("铜川", 44), ("平度", 44), ("佛山", 44), ("海口", 44), ("江门", 45), ("章丘", 45), ("肇庆", 46), ("大连", 47), ("临汾", 47), ("吴江", 47), ("石嘴山", 49), ("沈阳", 50), ("苏州", 50), ("茂名", 50), ("嘉兴", 51), ("长春", 51), ("胶州", 52), ("银川", 52), ("张家港", 52), ("三门峡", 53), ("锦州", 54), ("南昌", 54), ("柳州", 54), ("三亚", 54), ("自贡", 56), ("吉林", 56), ("阳江", 57), ("泸州", 57), ("西宁", 57), ("宜宾", 58), ("呼和浩特", 58), ("成都", 58), ("大同", 58), ("镇江", 59), ("桂林", 59), ("张家界", 59), ("宜兴", 59), ("北海", 60), ("西安", 61), ("金坛", 62), ("东营", 62), ("牡丹江", 63), ("遵义", 63), ("绍兴", 63), ("扬州", 64), ("常州", 64), ("潍坊", 65), ("重庆", 66), ("台州", 67), ("南京", 67), ("滨州", 70), ("贵阳", 71), ("无锡", 71), ("本溪", 71), ("克拉玛依", 72), ("渭南", 72), ("马鞍山", 72), ("宝鸡", 72), ("焦作", 75), ("句容", 75), ("北京", 79), ("徐州", 79), ("衡水", 80), ("包头", 80), ("绵阳", 80), ("乌鲁木齐", 84), ("枣庄", 84), ("杭州", 84), ("淄博", 85), ("鞍山", 86), ("溧阳", 86), ("库尔勒", 86), ("安阳", 90), ("开封", 90), ("济南", 92), ("德阳", 93), ("温州", 95), ("九江", 96), ("邯郸", 98), ("临安", 99), ("兰州", 99), ("沧州", 100), ("临沂", 103), ("南充", 104), ("天津", 105), ("富阳", 106), ("泰安", 112), ("诸暨", 112), ("郑州", 113), ("哈尔滨", 114), ("聊城", 116), ("芜湖", 117), ("唐山", 119), ("平顶山", 119), ("邢台", 119), ("德州", 120), ("济宁", 120), ("荆州", 127), ("宜昌", 130), ("义乌", 132), ("丽水", 133), ("洛阳", 134), ("秦皇岛", 136), ("株洲", 143), ("石家庄", 147), ("莱芜", 148), ("常德", 152), ("保定", 153), ("湘潭", 154), ("金华", 157), ("岳阳", 169), ("长沙", 175), ("衢州", 177), ("廊坊", 193), ("菏泽", 194), ("合肥", 229), ("武汉", 273), ("大庆", 279)] geo = Geo("全国主要城市空气质量", "data from pm2.5", 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, 200], maptype='china', visual_text_color="#fff", symbol_size=10, is_visualmap=True) geo.render("全国主要城市空气质量.html") # 生成html文件
def load_data(): lines = [] data = [] with open('haiwang.txt','r',encoding='utf-8') as f: lines = f.readlines() for item in lines: cityinfo = item.split() print(cityinfo[0],cityinfo[1]) data.append((cityinfo[0],cityinfo[1])) geo = Geo('海王全国观众分布','data from maoyan',title_color="#fff",title_pos="center",width=1200,height=600,background_color= "#404a59") attr,value = geo.cast(data) geo.add("",attr,value,type="heatmap", is_random=True, visual_range=[0, 1600], visual_text_color="#fff", symbol_size=15, is_visualmap=True,border_color="#111", geo_cities_coords=None) geo.render('hai_wang_guan_zhong.html')
class PlotGeo: def __init__(self): self.data = {{'label': []}, } self.titles = ['全国销售情势图', 'data from sale'] self.indexes = [] self.geo = Geo() self.script_list = self.geo.get_js_dependencies() def plot_geo(self, dat, tit, ind): self.data = dat self.titles = tit self.indexes = ind self.geo = Geo(self.titles[0], self.titles[1], title_pos='center', title_color='#fff', width=1200, height=600, background_color='#404a59') for label in self.data.keys(): self.geo.add(label, self.indexes, self.data[label], visual_range=[0, 200], visual_text_color='#fff', symbol_size=15, is_visualmap=True) return self.geo.render_embed()
def test_geo_china_scatter(): geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style) 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', ) html_content = geo._repr_html_() assert '"type": "scatter"' in html_content assert '"type": "heatmap"' not in html_content assert '"type": "effectScatter"' not in html_content
def heat_diagram(): df = read_mongo(db, MONGO_DB, {'_id': 0, 'citys': 1}) i = [i for i in df['city_name']] j = [j for j in df['nums']] data = list(zip(i, j)) 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, 55000], visual_text_color="#fff", symbol_size=15, is_visualmap=True) geo.render('旅游景点热力图.html')
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')
def test_full_example(): data = [("广州", 45), ("漳州", 35), ("A市", 43)] geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style) coordinate = geo.get_coordinate("广州") assert 2 == len(coordinate) with assert_raises(ValueError): geo.get_coordinate("A市", raise_exception=True) attr, value = geo.cast(data) with assert_raises(ValueError): 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, ) geo.add_coordinate("A市", 119.3, 26.08) 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, ) geo.render()
def create_map(df): # 绘制地图 value = [i for i in df['line']] attr = [i for i in df['city']] geo = Geo( "已开通地铁城市分布情况", title_pos='center', title_top='0', width=800, height=400, title_color="#fff", background_color="#404a59", ) geo.add("", attr, value, is_visualmap=True, visual_range=[0, 25], visual_text_color="#fff", symbol_size=15) geo.render("已开通地铁城市分布情况.html")
def guo_report(request): # select province, difi_re_num from REPORT_REG ret = """select city, difi_re_num from REPORT_REG a, province_to_city b where a.province=b.province""" data_list = exc_sql(ret) attr = [i[0] for i in data_list] value = [i[1] for i in data_list] geo = Geo("全国各地用户注册图", width=1200, height=600) geo.add("各省注册量", attr, value, type="effectScatter", border_color="#ffffff", symbol_size=2, is_label_show=True, label_text_color="#00FF00", label_pos="inside", symbol_color="yellow", geo_normal_color="#006edd", geo_emphasis_color="#0000ff") data = {'data': geo.render_embed()} return render(request, 'guo_report.html', data)
def showHotMap(): attr, value, geo_cities_coords = getHotMapData() style = Style(title_color="#fff", title_pos="center", width=800, height=600, background_color="#132F3D") geo = Geo('浙江水利厅发文热力图', **style.init_style) geo.add("", attr, value, visual_range=[0, 8000], symbol_size=15, visual_text_color="#fff", is_piecewise=True, is_visualmap=True, maptype='浙江', geo_cities_coords=geo_cities_coords) #geo.add("", attr, value, type="effectScatter", is_random=True, maptype = '浙江',effect_scale=4,geo_cities_coords=geo_cities_coords) #geo.render('浙江水利厅发文热力图.html') return geo
def test_geo(): geo = Geo("大蒜价格和地区的关系", "", title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') attr = arealist value = pricelist geo.add("", attr, value, visual_range=[0, 15], visual_split_number=0.5, visual_text_color="#fff", symbol_size=16, is_visualmap=True) geo.show_config() geo.render('大蒜1.html')
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("全国主要城市空气质量", "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
def drawAll_WithDifferentColor(weizhi, attr, value): #用不同的颜色表示不同的时区上的店 geo = Geo("星巴克门店在全球不同时区的分布情况", "正代表东,负代表西,数字代表第几个时区,缺失时区值的店铺没有显示", title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') geo.add("", attr, value, visual_range=[-10, 10], visual_text_color="#fff", maptype="world", symbol_size=15, geo_cities_coords=weizhi, is_visualmap=True, is_piecewise=True, visual_split_number=21) geo.render("timezone_geo.html")
def geo_picture(data, city_sets): # 导入相关工具库 # 导入Geo模块进行城市数据分析 from pyecharts import Geo useless_cities = [] city_infos = [] for i in range(len(data)): geo = Geo("《流浪地球》全国观影粉丝分布图", "data from Maoyan", title_color="#fff", title_pos="center", width=1000, height=750, background_color='#404a59') attr, value = geo.cast(data) try: geo.add("", attr, value, visual_range=[0, 200], maptype='china', type="effectScatter", visual_text_color="#fff", symbol_size=10, is_visualmap=True) except Exception as e: # print(e) # 在异常信息中提取无法被pyecharts识别的城市 city = str(e).split()[-1] # 将不能识别的城市名称收集到列表中 useless_cities.append(city) # 剔除无法识别的城市信息 city_sets.pop(city) city_infos = geo_city_infos(city_sets) data = city_infos #生成html文件 geo.render("全国观影粉丝分布图.html") return geo, city_infos, useless_cities
def demo1(): data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15), ("赤峰", 16), ("青岛", 18), ("乳山", 18), ("金昌", 19), ("泉州", 21), ("莱西", 21), ("日照", 21), ("胶南", 22), ("南通", 23), ("拉萨", 24), ("云浮", 24), ("梅州", 25)] 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, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True) geo.show_config() geo.render()
def create_city(cities): fc = [] for v in cities: if v != '' and v != '海淀' and v != '延边': fc.append(v) # 统计每个城市出现的次数 data = Counter(fc).most_common(5) # 使用Counter类统计出现的次数,并转换为元组列表 print(data) # 根据城市数据生成地理坐标图 geo = Geo('好友位置分布', '', title_color='#fff', title_pos='center', width=1200, height=600, background_color='#404a59') attr, value = geo.cast(data) print(attr) print(value) geo.add('', attr, value, visual_text_color='#fff', symbol_size=15, is_visualmap=True, is_piecewise=True) geo.render('好友位置分布.html') # 根据城市数据生成柱状图 data_top10 = Counter(fc).most_common(10) # 返回出现次数最多的20条 bar = Bar('好友所在城市TOP10', '', title_pos='center', width=1200, height=600) attr, value = bar.cast(data_top10) bar.add('', attr, value, is_visualmap=True, visual_text_color='#fff', is_more_utils=True, is_label_show=True) bar.render('好友所在城市TOP10.html')
def geo(self, title=None, data=None): """ 地图 :param title: 数据可视化的标题(字符串) :param data: {地名:value} 字典{'宿迁市': 89, '安康市': 46, '佳木斯市': 50,} :return:地图 """ data = data geo = Geo(title, 'data from AQI', title_color='#fff', \ title_pos='center', width=1200, height=600, background_color='#404a59') attr, value = geo.cast(data) # data is not.0 geo.add('', attr, value, visual_range=[0, 200], visual_text_color='#fff', symbol_size=15, is_visualmap=True, is_piecewise=True, visual_split_number=6) self.page.add(geo) self.page.render()
def DrawGeo(city_names): data = [] for cn in city_names: temp = qr.get_data(cn) data.append((cn, temp['pm25'])) geo = Geo('全国部分城市空气质量', '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, 200], visual_text_color='#fff', symbol_size=15, is_visualmap=True, type='effectScatter') geo.render('weatherGeo.html')
def unicorn_china(data): data = data.groupby(by='Headquarter').count() data.sort_values(by='Company', ascending=False, inplace=True) value = list(data['Company'].values) attr = list(data.index) # print(value,attr) map = Geo("大中华区独角兽公司分布", '北京突出', title_color="#fff", title_pos="center", background_color='#404a59') # type="effectScatter", is_random=True, effect_scale=5 使点具有发散性 # 发散圆点图 map.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5, visual_range=[0, 80], visual_text_color="#fff", symbol_size=5, is_visualmap=True, ) map.render(path='./国内独角兽公司城市分布.png', pixel_ration=1)
def render_city(dir, cities): # 对城市数据和坐标文件中的地名进行处理 handle(cities) # 使用Counter类统计出现的次数,并转换为元组列表 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, 600], visual_text_color="#fff", symbol_size=15, is_visualmap=True) geo.render(dir + r"\geo.html")
def plotmap(): geo = Geo("湖南省地质中学G1115班同学本科毕业去向(持续更新)", "Made by YJT, Module provided by pyecharts", title_color="#fff", title_pos="center", width=1366, height=768, page_title ='湖南省地质中学G1115班同学本科毕业去向', background_color="#404a59") with open("G1115.txt") as file: temp = file.readline().split(":") data = [] while temp != [""]: data.append(tuple(temp)) temp = file.readline().split(":") attr, value = geo.cast(data) geo.add("", attr, value, type="effectScatter", is_random=False, maptype='world', effect_scale=5, tooltip_formatter=formatter_for_tooltip, symbol_size=10, #geo_normal_color="#F0F8FF", #geo_emphasis_color="#4169E1", label_formatter="{b}", label_text_size=15, label_emphasis_textsize=15, label_color=['#FFFFFF']*len(attr), label_emphasis_textcolor='#FFFFFF', #tooltip_tragger_on='click', tooltip_font_size=15, tooltip_background_color="rgba(50,50,50,0.3)",) geo.render("G1115.html")
def line3d(): # --------------------地图--------------------------------- a = list(JobMsg.objects.all().values_list('job_address')) # print(a) city_names = [] for city_id in a: try: city_names.append(JobCitys.objects.get(cityid=city_id[0]).cityname) except: pass ss = {} for i in city_names: if city_names.count(i) >= 1: ss[i] = city_names.count(i) # print(ss) hh = [] for i, j in ss.items(): if i not in ['丽江', '达州', '黔西南']: hh.append((i, j)) # print(hh) geo = Geo("城市与需求量关系图", title_color="#fff", title_pos="center", width=1000, height=600, background_color='#404a59') attr, value = geo.cast(hh) geo.add("", attr, value, visual_range=[0, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True) return geo
def city_distribution_geo(self, cities): # 统计城市名称,该城市出现的次数 for city in cities: if city == '': cities.remove(city) coun = Counter(cities) # 处理地图库数据 city_name = self.city_handles(list(coun)) city_dict = dict(coun) city_num = [] for city in city_name: city_num.append(city_dict[city]) # print('%s : %s' %(len(city_name), city_name)) # print('%s : %s' %(len(city_num), city_num)) city_max = max(city_num) geo = Geo('评论者城市分布情况', "data from maoyan", title_color="#fff", title_pos="center", width=1200, height=600, background_color="#404a59") geo.add('', city_name, city_num, type='scatter', maptype='china', visual_range=[0, city_max], visual_text_color="#fff", symbol_size=15, is_visualmap=True # is_piecewise=True # visual_split_number=10 ) geo.render(self.path + r'/city_geo.html')
def _draw_hot1(day, hour, minute, tp): """ pycharts热力图 :param day: :param hour, minute: :param tp: :return: """ geo = Geo( "上海市出租车", "data from 强生出租车", title_color="#fff", title_pos="center", width=500, height=400, background_color="#404a59", ) data = da.hot_deal(day, hour, minute, tp) for i in data.index: geo.add_coordinate('%s' % i, data.loc[i, 'lon'], data.loc[i, 'lat']) list1 = [('%s' % i, data.loc[i, 'num']) for i in data.index] attr, value = geo.cast(list1) geo.add( "", attr, value, maptype=u'上海', coordinate_region=u'上海', # type='heatmap', is_visualmap=True, visual_text_color="#fff", visual_range=[1, 10], symbol_size=2, is_roam=False) return geo
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 = dumps_actual_options(geo.options) expected = get_fixture_content(fixture) for a, b in zip(actual_options.split("\n"), expected.split("\n")): eq_(a.strip(), b.strip())
def draw_city_pic(csv_file): page = Page(csv_file+":城市职位分析") d = pd.read_csv(csv_file, engine='python', encoding='utf-8') # 读取CSV转为dataframe格式,并丢弃评论为空的的记录 city_info = d['city'].value_counts() geo = Geo("", "城市职位分布", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff") geo.add("", city_info.index, city_info.values, maptype="china",visual_range=[1, 200], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=10, symbol_size=15, is_visualmap=True, is_more_utils=True) geo.render(csv_file[:-4] + "_城市职位dotmap.html") page.add_chart(geo) geo2 = Geo("", "城市职位热力图",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff",) geo2.add("", city_info.index, city_info.values, type="heatmap", is_visualmap=True, visual_range=[1, 200],visual_text_color='#fff', is_more_utils=True) geo2.render(csv_file[:-4]+"_城市职位heatmap.html") # 取CSV文件名的前8位数 page.add_chart(geo2) city_pie = pyecharts.Pie("", "城市职位饼图", title_pos="right", width=1200, height=600) city_pie.add("", city_info.index, city_info.values, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') city_pie.render(csv_file[:-4] + "_城市职位饼图.html") # 取CSV文件名的前8位数 page.add_chart(city_pie) page.render(csv_file[:-4] + "_城市分析汇总.html")
def city_avg_salary(): data = sel_place_avg_salary() print(data) geo = Geo("全国招聘薪资水平热力图", "数据来源:拉勾网", title_color="#000", title_pos="center", width=1120, height=800, background_color='#F4F3EF') attr, value = geo.cast(data) geo.add( "", attr, value, type="heatmap", #类型热力图 is_label_show=True, is_visualmap=True, visual_range=[0, 20], visual_text_color='#000', geo_normal_color="#FFFACD", geo_emphasis_color="#FFEC8B") return geo
def test_geo_formatter_func(): style = Style( title_color="#fff", title_pos="center", width=1200, height=600, background_color="#404a59", ) data = [("汕头市", 50), ("汕尾市", 60), ("揭阳市", 35), ("阳江市", 44), ("肇庆市", 72)] geo = Geo("广东城市空气质量", "data from pm2.5", **style.init_style) attr, value = geo.cast(data) geo.add( "", attr, value, maptype="广东", type="effectScatter", tooltip_formatter=geo_formatter, is_random=True, effect_scale=5, is_legend_show=False, ) assert "function geo_formatter(" in geo._repr_html_()
def geo_graph(brand): """ 热力图绘制 :param brand: 汽车品牌 :return: """ data = car_city(brand) geo = Geo(brand, brand + "distribution", 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, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True) geo.render()
def create_map(self, city, value, name="观影地区分布"): """Scatter类型地图""" geo = Geo(name, "数据来源于猫眼", title_color="#fff", title_pos="center", width=800, height=500, background_color='#404a59') # 添加城市坐标 geo.add_coordinate_json(CITY_JSON_FILE) geo.add("", city, value, is_label_show=True, is_roam=True, visual_range=[0, 40], visual_text_color="#fff", symbol_size=15, is_visualmap=True) geo.render(MAP_PATH) print("地理分布图【成功】")
def draw_citys_pic(csv_file): page = Page(csv_file+":评论城市分析") info = count_city(csv_file) geo = Geo("","Ctipsy原创",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff") while True: # 二次筛选,和pyecharts支持的城市库进行匹配,如果报错则删除该城市对应的统计 try: attr, val = geo.cast(info) geo.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=6, symbol_size=15, is_visualmap=True) except ValueError as e: e = str(e) e = e.split("No coordinate is specified for ")[1] # 获取不支持的城市名称 info.pop(e) else: break info = sorted(info.items(), key=lambda x: x[1], reverse=False) # list排序 # print(info) info = dict(info) #list转dict # print(info) attr, val = [], [] for key in info: attr.append(key) val.append(info[key]) geo1 = Geo("", "评论城市分布", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff") geo1.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=10, symbol_size=15, is_visualmap=True, is_more_utils=True) #geo1.render(csv_file + "_城市dotmap.html") page.add_chart(geo1) geo2 = Geo("", "评论来源热力图",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff",) geo2.add("", attr, val, type="heatmap", is_visualmap=True, visual_range=[0, 50],visual_text_color='#fff', is_more_utils=True) #geo2.render(csv_file+"_城市heatmap.html") # 取CSV文件名的前8位数 page.add_chart(geo2) bar = Bar("", "评论来源排行", title_pos="center", width=1200, height=600 ) bar.add("", attr, val, is_visualmap=True, visual_range=[0, 100], visual_text_color='#fff',mark_point=["average"],mark_line=["average"], is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45) #bar.render(csv_file+"_城市评论bar.html") # 取CSV文件名的前8位数 page.add_chart(bar) pie = Pie("", "评论来源饼图", title_pos="right", width=1200, height=600) pie.add("", attr, val, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') #pie.render(csv_file + "_城市评论Pie.html") # 取CSV文件名的前8位数 page.add_chart(pie) page.render(csv_file + "_城市评论分析汇总.html")
import datetime url = "http://www.86pm25.com/paiming.htm" head = { 'Referer': 'http://www.86pm25.com/city/Dazhou.html', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36' } html = requests.get(url, headers=head) html.encoding = 'utf-8' soup = BeautifulSoup(html.text, "lxml") data1 = soup.find(id="goodtable").find_all(name='a') data2 = str(soup.find(id='goodtable').find_all(name='td')) data = re.findall(r'<td>(\d{1,3}.)</td>', data2) with open("城市.txt", 'r') as f: CityList = f.read() city = [] for i in range(0, 367): if str(data1[i].string) in CityList: citytuple = (data1[i].string, int(data[i])) city.append(citytuple) geo = Geo("全国主要城市空气质量实时监控", "实时:" + str(datetime.datetime.now()), title_color="#fff", title_pos="center", width='100%', height=790, background_color='#404a59') attr, value = geo.cast(city) geo.add("", attr, value, visual_range=[0, 150], maptype='china', visual_text_color="#fff", symbol_size=13, is_visualmap=True) page = Page() page.add(geo) page.render("全国主要城市空气质量实时监控.html") webbrowser.open("全国主要城市空气质量实时监控.html", new=0, autoraise=True)
# 全国城市地图示例 from pyecharts import Geo data = [ ("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15), ("惠州", 37),("江阴", 37),("蓬莱", 37),("韶关", 38),("嘉峪关", 38),("广州", 38), ("张家港", 52),("三门峡", 53),("锦州", 54),("南昌", 54),("柳州", 54),("三亚", 54), ("呼和浩特", 58),("成都", 58),("大同", 58),("镇江", 59),("桂林", 59),("张家界", 59), ("北京", 79),("徐州", 79),("衡水", 80),("包头", 80),("绵阳", 80),("乌鲁木齐", 84), ("菏泽", 194),("合肥", 229),("武汉", 273),("大庆", 279)] geo = Geo( "全国部分城市空气质量", title_color="#fff", title_pos="center", width=800, height=600, background_color="#404a59", ) attr, value = geo.cast(data) geo.add( "", attr, value, visual_range=[0, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True, ) geo.render('result.地理坐标系图.全国城市地图示例.html')