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
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 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
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 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
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
def echarts_cate_draw(locations, labels, file_path, title="地域分布图", subtitle="location distribute", point_size=7): """ 依据分类生成地域分布的echarts散点图的html文件. :param locations: 样本的省市区, pandas的dataframe类型. :param labels: 长度必须和locations相等, 代表每个样本所属的分类. :param file_path: 生成的html文件路径. :param title: 图表的标题 :param subtitle: 图表的子标题 :param point_size: 每个散点的大小 """ _base_input_check(locations) if len(locations) != len(labels): from .exceptions import CPCAException raise CPCAException("locations的长度与labels长度必须相等") from pyecharts import Geo geo = Geo(title, subtitle, title_color="#000000", title_pos="center", width=1200, height=600, background_color='#fff') _geo_update(geo) uniques = set(list(labels)) def _data_add(_geo, _cate_keys, _category): real_keys = [] for cate_key in _cate_keys: if latlng.get(cate_key): real_keys.append(cate_key) attr = real_keys value = [1] * len(real_keys) geo.add(_category, attr, value, symbol_size=point_size, legend_pos="left", legend_top="bottom", geo_normal_color="#fff", geo_emphasis_color=" #f0f0f5") for category in uniques: cate_locations = locations[labels == category] _data_add( geo, zip(cate_locations["省"], cate_locations["市"], cate_locations["区"]), category) geo.render(file_path)
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 create_charts(): page = Page() 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)] style = Style(title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') chart = Geo("全国", "data from", **style.init_style) attr, value = chart.cast(data) chart.add("", attr, value, is_visualmap=True, visual_text_color='#000', is_label_show=True) page.add(chart) return page
def __init__(self): csv_path = os.path.abspath( os.path.join(os.path.dirname(__file__), '..')) csv_path = os.path.join(csv_path, 'Lagou.csv') self.data = pd.read_csv(csv_path, header=None, encoding='utf-8') self.geo = Geo('工资分布图(平均值)', title_color='#000', title_pos='center', width=1200, height=600)
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 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 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 create_charts(): page = Page() data = get_data() chart = Geo("python招聘分布", "data from 拉勾网") attr, value = chart.cast(data) chart.add("", attr, value, type="heatmap", is_visualmap=True, visual_range=[0, 180], visual_text_color='white', is_legend_show=False) page.add(chart) page.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 mapMaking(task_id): client = pymongo.MongoClient("127.0.0.1", 27017) list = [] dict = {} list1 = [] try: db = client.crawlData # 连接test数据库 collection = db.taobao # 访问test数据库中things集合 for m in collection.find({"task_id": task_id}, { "address": 1, "_id": 0 }): if m['address'] in citys: list.append(m['address']) except: pass finally: client.close() # print list # 生成关系,查找键值 for index in list: # 遍历词语列表 if index in dict: dict[index] += 1 # 根据字典键访问键值,如果该键在字典中,则其值+1 else: dict[index] = 1 # 如果键不在字典中,则设置其键值为1 # print dict #{u'\u4e0a\u6d77': 1, u'\u9633\u6c5f': 6, u'\u6210\u90fd': 1, u'\u91d1\u534e': 1} for item in dict.items(): # 化成列表类型 list1.append(item[0]) list1.append(item[1]) # print len(list1) list2 = [] for i in range(0, len(list1), 2): # 拼成pycharts能够输入的格式,步长为2 a = (list1[i], list1[i + 1]) list2.append(a) data = list2 geo = Geo(u"商品在全国售卖主要城市", u"商品", title_color="#fff", title_pos="center", width=1000, height=600, background_color='#404a59') geo.height = 800 geo.width = 1500 attr, value = geo.cast(data) geo.add("", attr, value, visual_range=[0, 60], maptype='china', visual_text_color="#fff", symbol_size=10, is_visualmap=True) geo.render("static/maps/map" + task_id + ".html") # 生成html文件
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 show_map_school(begin_year, end_year): ''' 用地图展示各学校的排名,这样可以观察地域与学校排名的关系 ''' datas = deal_ruanke.ranking_ruanke(begin_year, end_year) university_name = (list)(datas.keys()) ranking_datas = (list)(datas.values()) timeline = Timeline(is_auto_play=False, timeline_bottom=0, width=stand_width, height=500) for i in range(begin_year, end_year + 1): data = [] dict = {} nan = '' for j in range(0, len(university_name)): line = [] line.append(university_name[j]) if (ranking_datas[j][i - begin_year] == "nan"): continue line.append(ranking_datas[j][i - begin_year]) line_tuple = (tuple)(line) data.append(line_tuple) dict[university_name[j]] = ranking_datas[j][i - begin_year] if (i == 2016): nan = "(云南大学,青海大学,西藏大学未纳入排名)" geo = Geo(str(i) + "年度全国大学排名" + nan, "全国大学排名", title_color="#000", title_pos="center", width=1600, height=400, background_color='#DCDCDC') attr, value = geo.cast(data) geo.add("", attr, value, visual_range=[0, 600], maptype='china', visual_text_color="#000", symbol_size=20, is_visualmap=True, is_roam=False, visual_top="center", geo_normal_color="#404a59", visual_range_text=["high", "low"], visual_range_color=['#50a3ba', '#faef61', '#d94e5d'], label_formatter="{c0}", tooltip_formatter="{b}: [经度(E),纬度(N),排名] {c}名") geo timeline.add(geo, str(i) + '年') return timeline
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 geographical_location_GDP_ratio_distribution(): data = pd.read_excel("./data/car_sales_data.xlsx", sheet_name=u"人均GDP", encoding='utf-8') data.columns = [str(col).split('-')[0] for col in data.columns] float_cols = [str(year) for year in range(1998, 2018)] not_replace = [ u'池州市', u'宣城市', u'眉山市', u'达州市', u'庆阳市', u'广安市', u'贺州市', u'来宾市', u'崇左市', u'临沧市', u'固原市', u'中卫市', u'丽江市' ] data['city_name'] = data['city_name'].apply(lambda xx: xx.replace(u'市', '') if xx not in not_replace else xx) city_none = [u'黔西南布依族苗族自治州', u'乌兰察布', u'巴音郭楞蒙古自治州(库尔勒)'] data = data[~data['city_name'].isin(city_none)] data[float_cols] = data[float_cols].fillna(0).applymap(lambda xx: round(xx, 2) if xx else 0) cols_show = ['city_name'] + float_cols data = data[cols_show] data = calc_ratio_percent(data) data[range(1999, 2018)] = data[range(1999, 2018)].applymap(lambda xx: round(xx * 100, 2)) data.to_excel('./car_sales_visualization/GDP_ratio_distribution.xlsx') timeline = Timeline(is_auto_play=False, timeline_bottom=1250, width=2480, height=1330) for year in range(1999, 2018): dataset = [(city, sales) for city, sales in data[['city_name'] + [year]].values] geo = Geo( "%s - Car Sales Num Ratio Distribution" % year, "", title_pos="center", title_color="black", width=2480, height=1330, background_color='#ffffff' ) attr, value = geo.cast(dataset) geo.add( "", attr, value, type="effectScatter", is_visualmap=True, maptype='china', visual_range=[-100.0, 100.0], visual_text_color="black", effect_scale=5, symbol_size=5 ) timeline.add(geo, year) timeline.render('./car_sales_visualization/GDP_ratio_distribution.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)
def geographical_location_ratio_distribution(): data = pd.read_csv("./data/car_sales_volume_data.csv", encoding='utf-8') data = data[data['city'].str.len() > 1] data = calc_ratio_percent(data) data[range(1998, 2019)] = data[range(1998, 2019)].applymap(lambda xx: round(xx * 100, 4)) cols_show = ['city'] + range(1998, 2019) data = data[cols_show] city_none = [ u'三沙', u'中卫', u'临沧', u'丽江', u'克孜勒苏柯尔克孜自治州', u'其它', u'固原', u'新疆自治区直辖', u'普洱', u'河南省省直辖', u'海南省省直辖', u'湖北省省直辖' ] data = data[~data['city'].isin(city_none)] data.to_excel('./car_sales_visualization/car_sales_num_ratio.xlsx') timeline = Timeline(is_auto_play=False, timeline_bottom=1250, width=2480, height=1330) for year in range(1998, 2019): dataset = [(city, sales) for city, sales in data[['city'] + [year]].values] geo = Geo( "%s - Car Sales Num Ratio Distribution" % year, "", title_pos="center", title_color="black", width=2480, height=1330, background_color='#ffffff' ) attr, value = geo.cast(dataset) geo.add( "", attr, value, type="effectScatter", is_visualmap=True, maptype='china', visual_range=[-100, 100], visual_text_color="black", effect_scale=5, symbol_size=5 ) timeline.add(geo, year) timeline.render('./car_sales_visualization/car_sales_num_ratio.html')
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()
def Cast(self, name, method=None, message=None, max_bin=100): ''' casts data ,and filters data with stopwords :param name: colname :param method: to decide the func returns a dict or tuple(attr,value) :param message: a message the user gives,if not None, will be adding to stopwords :param max_bin: the max number of words on wordcloud :return: ''' string = "".join(self.GetOneCol(name)) brokewords = map( str.strip, open('./config/stopwords/stopwords.txt', "r", encoding="utf-8").readlines()) if message: brokewords = itertools.chain(brokewords, message.split(",")[:]) stopwords = "".join(brokewords) lis = dict( Counter([ tag.strip() for tag in analyse.extract_tags(string, max_bin) if tag.strip() not in stopwords ])) lis = sorted(lis.items(), key=lambda x: x[1], reverse=True) if method is None: return Geo.cast(lis) elif method == "dict": return {k[0]: k[1] for k in lis}
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')
def draw_city_geo(data): geo = Geo("全国妹子所在地分布", "制作人:afrunk", title_color="#fff", title_pos="left", 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 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 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')
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 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)
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 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')
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")
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('=', '_'))
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')
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")
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')
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_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 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_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 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文件
# 全国城市地图示例 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')
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)
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()