def load_file(): with open("去哪儿景点.csv", "r", encoding="utf-8") as csvfile: reader = csv.reader(csvfile) cityList = [] #根据规则读取文件中的每一行文字 for line in reader: if len(line[0].split('·')) > 1: city = City() city.cityName = line[0].split('·')[1] city.hotValue = float(line[5].split(' ')[1]) foundRepeatCity = 0 #获取城市名字cityName和热度信息hotValue #针对城市名字cityName做组合操作,也就是针对其做热点求和 for originCity in cityList: if originCity.cityName == city.cityName: originCity.hotValue = originCity.hotValue + city.hotValue foundRepeatCity = 1 break #过滤掉城市中没有在echart 备案信息 if foundRepeatCity == 0 and Geo().get_coordinate( name=city.cityName) != None and int( city.hotValue) != 0: cityList.append(city) # 生成输出信息,用来传入到echart中 outputGeoData = [] for city in cityList: if Geo().get_coordinate(name=city.cityName) != None and int( city.hotValue) != 0: outputGeoDataRecord = (city.cityName, int(city.hotValue) * 5) outputGeoData.append(outputGeoDataRecord) print(outputGeoData) return outputGeoData
def load_file(): #打开csv文件 with open("qunar.csv", "r") as csvfile: reader = csv.reader(csvfile) #开始绘图 cityList = [] #根据规则读取文件中的文字 for line in reader: if len(line[0].split('·')) > 1: city = City() city.cityName = line[0].split('·')[1] city.hotValue = float(line[5].split(' ')[1]) foundRepeatCity = 0 #获取城市名字和热度信息 #针对城市名字做联合操作,也就是针对其做热点求和 for originCity in cityList: if originCity.cityName == city.cityName: originCity.hotValue = originCity.hotValue + city.hotValue foundRepeatCity = 1 break if foundRepeatCity == 0 and Geo().get_coordinate( name=city.cityName) != None and int( city.hotValue) != 0: cityList.append(city) #生成输出信息,传入图标 outputGeoData = [] for city in cityList: if Geo().get_coordinate(name=city.cityName) != None and round( city.hotValue) != 0: outputGeoDataRecord = (city.cityName, int(city.hotValue) * 1.25) outputGeoData.append(outputGeoDataRecord) return outputGeoData
def geo_scatter(df) -> Geo: if df.empty is False: index = df.max() / df.mean() / 50 geo = ( Geo() .add_schema(maptype="china") ) for item in df.index: l = [[item, df.loc[item]]] geo.add(series_name=item, data_pair=l, symbol_size=df.loc[item] / df.mean() / index, ) geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) geo.set_global_opts(toolbox_opts=opts.ToolboxOpts(is_show=True), legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross'), # visualmap_opts=opts.VisualMapOpts(), # title_opts=opts.TitleOpts(title="Geo-基本示例"), ) else: geo = ( Geo() .add_schema(maptype="china") ) return geo
def load_file(): # 打开csv文件 with open('result.csv', 'r', encoding='UTF-8') as csvfile: reader = csv.reader(csvfile) cityList = [] # 根据规则读取文件中的每一行文字 for line in reader: if len(line[0].split('·')) > 1: city = City() city.cityName = line[0].split('·')[1] city.hotValue = float(line[5].split(' ')[1]) foundRepeatCity = 0 # 获取城市名字cityName和热度信息hotValue # 针对城市名字cityName做聚合操作,也就是针对其做热点求和 for originCity in cityList: if originCity.cityName == city.cityName: originCity.hotValue = originCity.hotValue + city.hotValue foundRepeatCity += 1 break # 过滤城市列表中 没有在echart 备案过的城市 if foundRepeatCity == 0 and Geo().get_coordinate( name=city.cityName) is not None and int( city.hotValue) != 0: cityList.append(city) # 生成输出信息,用来传入到echarts中 outputGeoData = [] for city in cityList: if Geo().get_coordinate(name=city.cityName) is not None and int( city.hotValue) != 0: outputGeoDataRecord = (city.cityName, int(city.hotValue) * 5) outputGeoData.append(outputGeoDataRecord) print(outputGeoData) return outputGeoData
def drawGeoMap(self, aStuData): sno, sname = aStuData['info'].split(SPLIT_CHAR) sdata = aStuData['data'] try: geo = Geo() def add_data(date, location): # print(location) try: longitude, latitude, address = location except: longitude, latitude, address = DEFAULT_Location geo.add_coordinate(date, longitude, latitude) geo.add(date, [(date, address)], type_=ChartType.EFFECT_SCATTER) geo.add_schema(maptype="china") # add data for date, data in sdata.items(): add_data(date, data) title = f'{sno} {sname} 位置动态' geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) geo.set_global_opts(legend_opts=opts.LegendOpts(orient='vertical', pos_left='left', pos_top='10%'), title_opts=opts.TitleOpts(title=title)) html_path = ospath_join(self.mapsDir, f'{sno}_{sname}.html') geo.render(html_path) except Exception as e: log.error(f'地图生成失败: {sno} {sname} - 可能是包含了文件名不可用的特殊字符', exc_info=True) self._signal.emit(f'错误:{sno} {sname} 地图生成失败!可能原因:工号或提交人姓名中包含文件名不可用的特殊字符,如:*。请修改后重试!')
def base_info(): geo = Geo() geo.add_schema(maptype="河南") # 加入自定义的点,格式为 # 地图形式 type_=ChartType.HEATMAP geo.add("geo", data, type_=ChartType.EFFECT_SCATTER) # is_show:是否显示经纬度 geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=10), title_opts=opts.TitleOpts(title="Geo-河南省地图")) return geo
def draw_map(data_pair, data_coordinate) -> Geo: # ->常常出现在python函数定义的函数名后面,为函数添加元数据,描述函数的返回类型,从而方便开发人员使用。 g = Geo() # 选择要显示的地图 g.add_schema(maptype="重庆", center=[106.531638,29.561081], itemstyle_opts=opts.ItemStyleOpts(color="#575D57")) # 使用add_coordinate(name, lng, lat)添加坐标点和坐标名称 for item in data_coordinate: g.add_coordinate(item['name'], item['lng'], item['lat']) # 将数据添加到定义的地图上 g.add('', data_pair, type_=GeoType.EFFECT_SCATTER, symbol_size=5) # type_=ChartType.HEATMAP # 设置样式 g.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\ .set_global_opts(visualmap_opts=opts.VisualMapOpts(min_=60, max_ = 200, is_piecewise=True),title_opts=opts.TitleOpts(title="重庆房源分布图")) return g
def base_info(): print(data) geo = Geo() geo.add_schema(maptype="china") # 加入自定义的点,格式为 # geo.add_coordinate("自定义点", 80.39770014211535,39.90779994986951) # 地图形式 type_=ChartType.HEATMAP geo.add("geo", data, type_=ChartType.EFFECT_SCATTER) # is_show:是否显示经纬度 geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(), title_opts=opts.TitleOpts(title="Geo-基本示例")) return geo
def create_city_map(df): df1 = df[df["country"] == "中国"] df1 = df1.copy() df1["city"] = df1["city"].str.replace("市", "") df_num = df1.groupby("city")["city"].agg( count="count").reset_index().sort_values(by="count", ascending=False) df_city = df_num["city"].values.tolist() df_count = df_num["count"].values.tolist() # 初始化配置 geo = Geo(init_opts=opts.InitOpts(width="800px", height="400px")) # 中国地图 geo.add("", [list(z) for z in zip(df_city, df_count)], "china") # 设置全局配置项,标题、工具箱(下载图片)、颜色图例 geo.set_global_opts( title_opts=opts.TitleOpts(title="抖音大V城市分布情况", pos_left="center", pos_top="0"), toolbox_opts=opts.ToolboxOpts(is_show=True, feature={"saveAsImage": {}}), # 设置数值范围0-600,is_piecewise标签值连续 visualmap_opts=opts.VisualMapOpts(is_piecewise=True)) geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) map.render("抖音大V城市分布情况.html")
def load_file(): with open("qunar.csv", "r") as csvfile: reader = csv.reader(csvfile) city_list = [] # 逐行读取 for line in reader: if len(line[0].split('·')) > 1: city = City() city.city_name = line[0].split('·')[1] city.hot_value = float(line[5].split(' ')[1]) found_repeat_city = 0 # 按城市热点求和 for origin_city in city_list: if origin_city.city_name == city.city_name: origin_city.hot_value += city.hot_value found_repeat_city = 1 break # 过滤掉城市没有在echart备案的信息 if found_repeat_city == 0 \ and Geo().get_coordinate(name=city.city_name) is not None \ and int(city.hot_value) != 0: city_list.append(city) # 生成输入信息,用来传入到echart中 output_geo_data = [] for city in city_list: output_geo_data_record = (city.city_name, int(city.hot_value * 5)) output_geo_data.append(output_geo_data_record) print(output_geo_data) return output_geo_data
def map_985_211(): global wid, hei df = pd.read_csv('data/211_985.csv') #前39所为985 df_985 = df.iloc[:39] df_211 = df.iloc[39:] df_985_num = df_985.groupby('所在地').count().iloc[:, 0] df_211_num = df_211.groupby('所在地').count().iloc[:, 0] c = ( Geo(init_opts=opts.InitOpts(width=wid, height=hei)).add_schema( maptype="china").add("985", list(df_985_num.iteritems()), type_=ChartType.HEATMAP).add( "211", list(df_211_num.iteritems()), type_=ChartType.HEATMAP). set_global_opts( title_opts=opts.TitleOpts(title="985_211全国分布"), visualmap_opts=opts.VisualMapOpts(max_=5), # visualmap_opts=opts.VisualMapOpts(is_piecewise=True,pieces=[ # {"min":10, "max": 30}, # {"min": 5, "max": 10}, # {"value": 4}, # {"value": 3}, # {"min": 2,"max": 2}, # {"value": 1, "label": '1 一枝独秀', "color": 'grey'}, # ] # ) )) return c
def geo_charts(content): """绘制世界地图""" zip_data = content[0] start_city = content[1] geo = (Geo().add_schema( maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#00000"), ).add( "", data_pair=zip_data, type_=ChartType.EFFECT_SCATTER, color="white", ).add( "geo", data_pair=start_city, type_=GeoType.LINES, effect_opts=opts.EffectOpts(symbol=SymbolType.RECT, symbol_size=6, color="yellow", is_show=True), linestyle_opts=opts.LineStyleOpts(curve=0.2), ).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts(title_opts=opts.TitleOpts( title="Python开发工程师可视化界面"))) return geo
def geo_lines_background() -> Geo: c = ( Geo() .add_schema( maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"), ) .add( "", [("广州", 55), ("北京", 66), ("杭州", 77), ("重庆", 88)], type_=ChartType.EFFECT_SCATTER, color="white", ) .add( "geo", [("广州", "上海"), ("广州", "北京"), ("广州", "杭州"), ("广州", "重庆")], type_=ChartType.LINES, effect_opts=opts.EffectOpts( symbol=SymbolType.ARROW, symbol_size=6, color="blue" ), linestyle_opts=opts.LineStyleOpts(curve=0.2), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="Geo-Lines-background")) ) return c
def geo_lines() -> Geo: c = ( Geo() .add_schema(maptype="china") .add( "", [("北京", 1), ("重庆", 2), ("长沙", 3), ("长春", 4), ("成都", 5), ("大连", 6), ("广州", 7), ("贵阳", 8), ("合肥", 9), ("杭州", 10), ("哈尔滨", 11), ("海口", 12), ("济南", 13), ("昆明", 14), ("柳州", 15), ("绵阳", 16), ("潞西市", 17), ("南宁", 18), ("南京", 19), ("沈阳", 20), ("三亚", 21), ("上海", 22), ("天津", 23), ("徐州", 24), ("义乌", 25), ("郑州", 26), ("张家界", 27)], type_=ChartType.EFFECT_SCATTER, color="#ffa022" ) .add( "", [("揭阳", "北京"), ("揭阳", "重庆"), ("揭阳", "长沙"), ("揭阳", "长春"), ("揭阳", "成都"), ("揭阳", "大连"), ("揭阳", "广州"), ("揭阳", "贵阳"), ("揭阳", "合肥"), ("揭阳", "杭州"), ("揭阳", "哈尔滨"), ("揭阳", "海口"), ("揭阳", "济南"), ("揭阳", "昆明"), ("揭阳", "柳州"), ("揭阳", "绵阳"), ("揭阳", "潞西市"), ("揭阳", "南宁"), ("揭阳", "南京"), ("揭阳", "沈阳"),("揭阳", "三亚"), ("揭阳", "上海"), ("揭阳", "天津"), ("揭阳", "徐州"),("揭阳", "义乌"),("揭阳", "郑州"), ("揭阳", "张家界")], type_=ChartType.LINES, effect_opts=opts.EffectOpts( symbol=symbol_list[0], symbol_size=15, color='#a6c84c', period=6, trail_length=0, is_show=True # 特效图形的标记。有 RECT', 'DIAMOND', 'ARROW' 可选 ), linestyle_opts=opts.LineStyleOpts(curve=0.2, color='#46bee9', width=1, opacity=0.5), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="揭阳出发国内航线", subtitle="数能工作室制作", pos_left="center", title_textstyle_opts=opts.TextStyleOpts(color='black',font_size=20, font_weight="bold"), subtitle_textstyle_opts=opts.TextStyleOpts(color='black',font_size=15),item_gap=15)) ) return c
def geo_sichuan(title) -> Geo: c = (Geo().add_schema(maptype='四川').add( title, [list(z) for z in zip(Data.sichuan_city, Data.values())], type_=ChartType.HEATMAP).set_global_opts( visualmap_opts=opts.VisualMapOpts(max_=42, is_piecewise=True), title_opts=opts.TitleOpts(title='四川温度变化情况'))) return c
def city(self): sql = 'select city, count(1) counts from jobs group by city' results = self.query(sql) c = (Geo().add_schema(maptype="china").add( "城市热力图", list(results), type_=ChartType.HEATMAP, ).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( visualmap_opts=opts.VisualMapOpts(), ).render("拉钩城市热力图.html")) sql = 'select city,counts from (select city, count(1) counts from jobs group by city) a order by counts desc limit 20' results = self.query(sql) citys = [] values = [] for row in results: citys.append(row[0]) values.append(row[1]) c = (Bar().add_xaxis(citys).add_yaxis( "各城市的招聘数量 Top 20", values).set_global_opts(xaxis_opts=opts.AxisOpts( name_rotate=60, name="城市", axislabel_opts={"rotate": 45})).render("拉钩城市招聘图.html"))
def hotpoint(movie_name): #读取城市数据 with open(movie_name + '\\' + movie_name + 'dbplaces.txt', 'r+', encoding='utf-8-sig') as f: heat_1 = f.read() for i in heat_1: if i in string.punctuation: heat_1 = heat_1.replace(i, "") heat = heat_1.split() heat_dic = Counter(heat) #整理数据 heat_list = [] for place, times in heat_dic.items(): c_word = (place, times) heat_list.append(c_word) #出图 heat_map = (Geo().add_schema(maptype="china").add( "", heat_list).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( visualmap_opts=opts.VisualMapOpts(), title_opts=opts.TitleOpts(title=movie_name + " 豆瓣观影热点图", subtitle=None), toolbox_opts=opts.ToolboxOpts(is_show=True))) heat_map.render(movie_name + '\\' + movie_name + 'dbhotpoint.html')
def city_info(self): dict_city = dict() for friend in self.friends: key = friend['City'] if key not in dict_city.keys(): dict_city[key] = 1 else: dict_city[key] += 1 city = [] # max_num = 0 # 某个城市中最多的人数 for key, value in dict_city.items(): # 其他地区 if len(key) == 0: continue # 过滤英文等非市级 if len(key) >= 3: continue city.append(tuple((key, value))) # if value > max_num: # max_num = value # 地图标注 # geo = Geo("微信好友城市分布图", "data from WeChat", title_color="#fff", title_pos="center", # width=1200, height=600, background_color='#404a59') # attr, value = geo.cast(city) # geo.add("", attr, value, visual_range=[0, 50], visual_text_color="#fff", symbol_size=15, is_visualmap=True) # geo.show_config() geo = (Geo().add_schema(maptype="china").add("人数", )) geo.render("city.html")
def geo_base() -> Geo: c = (Geo().add_schema( maptype="china", itemstyle_opts=opts.ItemStyleOpts( color="#323c48", border_color="#111")).add( "人/平方千米", zip(list(df.地区), list(df.人口密度))).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="2018年36个主要城市的人口密度情况"), visualmap_opts=opts.VisualMapOpts(max_=2306.6, min_=18.7, is_piecewise=True, pieces=[{ 'min': 924, 'max': 2306.593060 }, { 'min': 602, 'max': 923.156006 }, { 'min': 362, 'max': 600.689035 }, { 'min': 18.781760, 'max': 361.142947 }]))) return c
def show_covid(): covid = (Geo().add_schema(maptype="澳大利亚").add_coordinate( "Sydney", 151.207, -33.868).add_coordinate("Melbourne", 144.963, -37.814).add_coordinate( "Brisbane", 153.028, -27.468).add_coordinate("Perth", 115.861, -31.952).add_coordinate( "Adelaide", 138.599, -34.929).add_coordinate( "Cold Coast", 153.431, -28).add_coordinate("Newcastle", 151.78, -32.93).add( "geo", [list(z) for z in zip(geo_city, geo_cov) ]).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( visualmap_opts=opts.VisualMapOpts( type_="size", max_=500, min_=0, range_text=[ 'Highly discussed', 'Rarely discussed' ]), title_opts=opts.TitleOpts( title="Twitter Covid Map"), legend_opts=opts.LegendOpts(is_show=False))) return covid
def geoHeatMap(self,area=None,data=None,maptype='china',title='热力图示例',subtitle='副标题'): ''' 热力图 param area: 省份的列表 type list 例如 ['吉林', '辽宁', '河北', '河南'] param data: 对应的值 type list 例如 [63,10,2,30] 应用场景 省份或者城市排行榜 # ['黑龙江', '吉林', '辽宁', '河北', '河南', '山东', '山西', '安徽', '江西', '江苏', '浙江', '福建', '台湾', '广东', # '湖南', '湖北', '海南', '云南', '贵州', '四川', '青海', '甘肃', '陕西', '内蒙古', '新疆', '广西', '宁夏', '西藏', # '北京','天津','上海','重庆','香港','澳门'] ''' area = area or Faker.provinces data = data or Faker.values() c = ( Geo() .add_schema(maptype=maptype) .add( "geo", [list(z) for z in zip(area, data)], type_=ChartType.HEATMAP, ) # .set_series_opts(label_opts=opts.LabelOpts(is_show=True)) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( visualmap_opts=opts.VisualMapOpts(), title_opts=opts.TitleOpts(title=title,subtitle=subtitle), ) ) chart_name = f'static/chart{self.index}_heatmap' make_snapshot(snapshot,c.render(f'{chart_name}.html'),f'{chart_name}.png',is_remove_html=True) self.index += 1
def geo_getmap() -> Geo: c = ( Geo().add_schema( maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"), ).add( "", allcases, type_=ChartType.EFFECT_SCATTER, # symbol_size="size", color="white", ).add( "", traces, type_=ChartType.LINES, # effect_opts=opts.EffectOpts( # symbol=SymbolType.ARROW, symbol_size=6, color="red" # ), linestyle_opts=opts.LineStyleOpts(curve=0.2), ).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts(title_opts=opts.TitleOpts( title="2019-nCoV Trace Map(China)"))) make_snapshot(snapshot, c.render(), "tracemap.png")
def ocean_export_lines(): data = pd.read_csv(r"F:\ftp\erbranch\OEin24hrs\data.csv") chargeable_weight = [] origin_dest = [] for index, row in data.iterrows(): chargeable_weight.append([row['DEST CITY'], row['CW']]) origin_dest.append([row['ORIGIN CITY'], row['DEST CITY']]) min_data = min([d[1] for d in chargeable_weight]) max_data = max([d[1] for d in chargeable_weight]) c = ( Geo().add_schema(maptype="world", is_roam=False).add_coordinate_json( json_file=current_app.config['STATIC_PATH'] + r"\world_cities.json" ).add( "Chargeable Weight", chargeable_weight, type_=GeoType.EFFECT_SCATTER, ).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).add( "geo", origin_dest, type_=GeoType.LINES, # is_polyline = True, # effect_opts=opts.EffectOpts(symbol=SymbolType.DIAMOND, symbol_size=5, color="blue",), linestyle_opts=opts.LineStyleOpts(curve=0.3, width=2, opacity=0.2, color='Red'), ).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts(title_opts=opts.TitleOpts( title="TSN Ocean Export LINES in 24 Hrs"), visualmap_opts=opts.VisualMapOpts( min_=min_data, max_=max_data))) return render_template('dashboard/ocean_export_lines.html', geo=c.dump_options())
def geo_line() -> Bar: db = getattr(g, "_db", None) col = db.trafficmodels users = col.distinct("user") list_place = [] for user in users: place = col.find_one({"user": user}, {"place": 1})["place"] places = get_all_IP(user) for p in places: list_place.append([place, p]) c = (Geo().add_schema(maptype="world").add_coordinate_json( json_file="world_country.json").add( "交互图", list_place, type_=ChartType.LINES, effect_opts=opts.EffectOpts(symbol=SymbolType.DIAMOND, symbol_size=6, color="blue"), linestyle_opts=opts.LineStyleOpts( curve=0.2, opacity=0.2, )).set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="总交互图"), tooltip_opts=opts.TooltipOpts(is_show=True))) return c
def _geo_chart() -> Geo: return ( Geo() .add_schema(maptype="china", center=[39, 117.7], zoom=9) .add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())]) .set_global_opts(visualmap_opts=opts.VisualMapOpts()) )
def geoLineCity(self, data) -> Geo: # 指定城市航班连接城市图 count = len(data[0]) city_Geoline = ( Geo(init_opts=opts.InitOpts( width='1000px', height='500px')).add_schema( maptype="china", zoom=1.1).add_coordinate_json( self.geo_file).add("", data[1], symbol_size=6, color='#725e82') # 标记点大小与颜色 .add( "", data[0], type_=ChartType.LINES, linestyle_opts=opts.LineStyleOpts(curve=0.1, width=1, color='#1685a9'), # 连线的宽度与颜色 effect_opts=opts.EffectOpts(is_show=False)) # 关闭涟漪效果 .set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts(title_opts=opts.TitleOpts( title="{}民航班机航线图".format(data[0][0][0]), subtitle='{},{}共有直飞全国{}个城市的航班'.format( self.today_ymd, data[0][0][0], count)))) return city_Geoline
def workarea_chart(df): # 统计各地区出现次数, 并转换为元组的形式 data = Counter(df.workarea).most_common() 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) # 添加数据点 # # type="effectScatter", is_random=True, effect_scale=5 使点具有发散性 # geo.add('', attr, value, type="effectScatter", visual_range=[0, 100], visual_text_color='#fff', symbol_size=5, is_visualmap=True, is_piecewise=True) # geo.show_config() # geo.render() geo = ( Geo() .add_schema(maptype="china") .add("", data) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( visualmap_opts=opts.VisualMapOpts(), title_opts=opts.TitleOpts(title="岗位城市分布图"), ) ) geo.render("./chart/workarea_chart.html")
def geo_lines() -> Geo: c = ( Geo( init_opts=opts.InitOpts(width="1000px",height="700px",theme=ThemeType.PURPLE_PASSION) ) .add_schema(maptype="china") .add( "航班数量", df2, type_=ChartType.EFFECT_SCATTER, #color="#ffa022" ) .add( "航线", df1, type_=ChartType.LINES, effect_opts=opts.EffectOpts( symbol=symbol_list[0], symbol_size=15, period=6, trail_length=0, is_show=True ), linestyle_opts=opts.LineStyleOpts(curve=0.2, width=1, opacity=0.5), ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="国内航线", #pos_left="center", title_textstyle_opts=opts.TextStyleOpts(font_size=30, font_weight="bold"), #subtitle_textstyle_opts=opts.TextStyleOpts(color='black',font_size=15) )) )
def geo_base() -> Geo: citys = [ '北京', '天津', '上海', '重庆', '石家庄', '太原', '西安', '济南', '长春', '哈尔滨', '南京', '杭州', '合肥', '南昌', '福州', '武汉', '长沙', '成都', '贵阳', '昆明', '广州', "郑州", "沈阳", '海口', '兰州', '西宁', '呼和浩特', '乌鲁木齐', '拉萨', '南宁', '银川' ] a_list = [(citys[i], [i, i * 2]) for i in range(len(citys))] # print(a_list) c = ( Geo(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS)) # 地图主题 .add_schema( maptype="china", is_roam=False, itemstyle_opts=opts.ItemStyleOpts(area_color='#E6E6FA')) # 地图颜色 .add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())]).add( "geo", [('南昌', 12), ('北京', 12), ('天津', 12), ('拉萨', 12), ('呼和浩特', 12), ('桂林', 12), ('沈阳', 12), ('乌鲁木齐', 12), ('海口', 12)], type_="effectScatter", itemstyle_opts=opts.ItemStyleOpts( border_color='#8A2BE2')) # 点的颜色 .set_series_opts(label_opts=opts.LabelOpts( is_show=False)).set_global_opts( visualmap_opts=opts.VisualMapOpts(series_index=[0][0]), title_opts=opts.TitleOpts(title="Geo-基本示例"), )) return c
def visual(self): with open('price.json', 'r', encoding='utf-8') as f: data = json.loads(f.read()) for n in data: price = data[n]['price'] if not price.isdigit(): # 清除价格不规范的数据 continue else: self.list_n.append((n, int(price))) house_map = ( Geo(init_opts=opts.InitOpts(width='1200px', height='500px')) .add_schema(maptype="沈阳", center=[123.434039, 41.798102], zoom=6) # 从json文件导入坐标值 .add_coordinate_json(r'position.json') .add('', self.list_n, symbol_size=10, color='#f20c00') .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) # 设置全局配置项 .set_global_opts ( visualmap_opts=opts.VisualMapOpts(type_='color', min_=5000, max_=18000), title_opts=opts.TitleOpts(title='沈阳市楼盘分布图', subtitle='数据来源:贝壳网(2020-01) 共{}个楼盘'.format(len(self.list_n))), ) # 设置系列配置项 .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) ) return house_map