def plot_geo_station_num(re_dic, to_path): dw = my_(config.MYSQL_BI_RW_ENV) muchcols_table = 'data_center.dc_stations_muchcols_enc' sqls = "select city scale,avg(latitude) avg_lat,avg(longitude) avg_lng,count(*) numbers from %s where name like '%%%s%%' group by city order by numbers desc" % ( muchcols_table, re_dic['name']) count_station_ = dw.to_dataframe(sqls) # count_station_['scale'] = count_station_['scale'].apply(lambda x: change_city(x, pro)) coords = {} for i in range(len(count_station_)): coords[count_station_.loc[i, 'scale']] = [count_station_.loc[i, 'avg_lng'], count_station_.loc[i, 'avg_lat']] num_Max = count_station_['numbers'].max() name_str = "油站名包含'%s':" % re_dic['name'] if re_dic['name'] else '' page = pyecharts.Page() style = pyecharts.Style(width=1300, height=860, background_color='#404a66', title_color="#eee", title_pos="center") geo = pyecharts.Geo(name_str + "油站分布地图", **style.init_style) geo.add("", count_station_['scale'], count_station_['numbers'], visual_text_color="#eee", is_legend_show=False, symbol_size=12, is_visualmap=True, visual_range=[0, num_Max], tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right', geo_cities_coords=coords) page.add(geo) chart2 = pyecharts.Bar(name_str + "油站分布柱状图", **style.init_style) chart2.add("", count_station_['scale'][:25], count_station_['numbers'][:25], visual_range=[0, num_Max], is_label_show=True, is_visualmap=True, visual_text_color='#eee') page.add(chart2) page.render(to_path)
def aboutMe(request): gauge = pyecharts.Gauge('', background_color='#f5f5f5') gauge.add('title', 'Percent', 80.66, scale_range=[0, 100], is_more_utils=True) gauge.show_config() result = gauge.render_embed() data = [("海门", 9), ("鄂尔多斯", 10), ("招远", 12), ("舟山", 18), ("齐齐哈尔", 10), ("盐城", 15)] geo = pyecharts.Geo("全国主要城市空气质量", "data from pm2.5", title_color="#000", title_pos="center", background_color='#f5f5f5') attr, value = geo.cast(data) geo.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5, is_more_utils=True) geo.show_config() result1 = geo.render_embed() attr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] v1 = [20, 33, 133, 124, 24, 313] v2 = [2.6, 12, 31, 241, 324, 134] bar = pyecharts.Bar('Bar Sample', background_color='#f5f5f5') bar.add("A", attr, v1, mark_line=["average"], mark_point=["min", "max"]) bar.add("B", attr, v2, mark_line=["average"], mark_point=["min", "max"], is_more_utils=True) bar_result = bar.render_embed() pie = pyecharts.Pie('', background_color="#f5f5f5") pie.add("", attr, v1, is_lable_show=True, lable_text_color="#156ACF", is_more_utils=True) pie.show_config() pie_result = pie.render_embed() liquid = pyecharts.Liquid('', background_color="#000") liquid.add("", [0.66, 0.5], ['diamond'], ['#294D99', '#156ACF'], is_more_utils=True) liquid.show_config() liquid_result = liquid.render_embed() return render_to_response( 'AboutMe.html', { 'result': result, 'result1': result1, 'bar_result': bar_result, 'pie_result': pie_result, 'liquid_result': liquid_result })
def t9(pa): # geo地图有不显示数值的bug加上下面的函数和 add的参数 label_formatter=label_formatter def label_formatter(params): return params.value[2] style = p.Style(title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') chart = p.Geo("山东省计算机职位分布", '数据来自齐鲁人才网,部分地区数据不准确', **style.init_style, subtitle_text_size=18) city = [i.replace('市', '') for i in next(pa)] # label_formatter=label_formatter防bug maptype去掉就是全国地图 chart.add("", city, next(pa), maptype='山东', visual_range=[0, 700], label_formatter=label_formatter, visual_text_color="#fff", is_legend_show=True, symbol_size=15, is_visualmap=True, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right', is_toolbox_show=False) return chart
def generateChinaMap(): 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 = pyecharts.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, 20], maptype='china', visual_text_color='#fff', symbol_size=10, is_visualmap=True) geo.render("全国空气质量检测.html") geo
def func(): page = pyecharts.Page() # step 1 # bar attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = pyecharts.Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) page.add(bar) # step 2 # scatter3D import random data = [[ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] for _ in range(80)] range_color = [ '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026' ] scatter3D = pyecharts.Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) page.add(scatter3D) # step 2 page.render() # step 3 # scatter_geo attr = ['11', '22'] data = ['1', '2'] scatter_geo = pyecharts.Geo("地理位置视图", width=1200, height=600) scatter_geo.add("", attr, data) page.add(scatter_geo) # step 2 page.render() # step 3 data = [["广州", "北京"], ["广州", "上海"]] scatter_geo = pyecharts.GeoLines("地理位置视图", width=1200, height=600) scatter_geo.add("上午航班", data, geo_normal_color='#ff00ff', geo_effect_period=9, geo_effect_color='#ff0000', geo_effect_symbol='arrow') data = [["广州", "南昌"], ["广州", "成都"]] scatter_geo.add("下午航班", data, geo_effect_traillength=1, geo_emphasis_color='#0000ff') page.add(scatter_geo) # step 2 page.render() # step 3
def geoData(self, chatroom=None): path = self.savedir + 'geoData.html' if chatroom: cmd = 'geoData %s' % chatroom myLogging(self.cmdFile, self.nickName, infoType='cmd', other=cmd) try: chatroom == self.instance.search_chatrooms( name=chatroom)[0]['NickName'] except Exception as reason: self.instance.send('在您的通讯录中没有找到该群[%s]' % chatroom) myLogging(self.errFile, self.nickName, infoType='err', other=cmd, info=reason) return memberList = self.getChatroomMembers(chatroom)['MemberList'] subtitle = self.nickName + ':' + chatroom else: cmd = 'geoData' myLogging(self.cmdFile, self.nickName, infoType='cmd', other=cmd) memberList = [each['Signature'] for each in self.frdInfoList] subtitle = self.nickName cities = [each['City'] for each in memberList] with open( os.path.dirname(os.path.abspath(__file__)) + '/city_coordinates.json', 'rb') as f: cityDict = json.load(f) data = [(each, cities.count(each)) for each in set(cities) if each in cityDict.keys()] geo = pyecharts.Geo('微信好友地理分布', subtitle, title_color="#fff", title_pos="center", background_color='#404a59') attr, value = geo.cast(data) geo.add("", attr, value, visual_range=[0, 100], visual_text_color="#fff", symbol_size=10, is_visualmap=True) geo.render(path) self.instance.send('@fil@%s' % path) os.remove(path) myLogging(self.cmdFile, self.nickName, infoType='cmd', status='success', other=cmd)
def read_region(q, star_date, end_date): # q = '11' keyword = q q = quote(q, 'utf-8') request_url = 'http://47.92.145.108:30003/youche/wordsArea.do?keyword=' + q + '&startDate=' + star_date + '&endDate=' + end_date s = urllib.request.urlopen(request_url).read().decode('utf8') json_data = json.loads(s) region_list = json_data['simba_insight_wordsareadata_get_response'][ 'word_areadata_list']['insight_words_area_distribute_data_d_t_o'] regions = [] values = [] min_num = 100000000 max_num = 0 for region in region_list: if 'cityname' in region: region_name = region['cityname'] if region_name == '内蒙': region_name = '内蒙古' if region_name.find('中国其它') > -1 or region_name.find('国外') > -1: continue regions.append(region_name) pv = int(region['impression']) if pv < min_num: min_num = pv if pv > max_num: max_num = pv values.append(region['impression']) # print(region['cityname']) geo = pyecharts.Geo(keyword + "--全国主要城市访问量", star_date + "~" + end_date, title_color="#fff", title_pos="center", width=1000, height=600, background_color='#404a59') # attr, value = geo.cast(data) geo.add("流量", regions, values, visual_range=[min_num, max_num], maptype='china', visual_text_color="#fff", symbol_size=10, is_visualmap=True) # map = Map(keyword+"~全国主要城市访问量", star_date+"~"+end_date, width=1200, height=600) # map.add("", regions, values, visual_range=[min_num, max_num], maptype='china', is_visualmap=True, is_label_show=True, # visual_text_color='#000') return geo
def create_Geo(): geo = pyecharts.Geo("最高气温地理坐标系图", '2018-4-16', title_color='#fff', title_pos='center', width=1200, height=600, background_color='#404a95') geo.add("最高气温", cities, highs, is_visualmap=True, visual_range=[0, 40], visual_text_color='#fff', symbol_size=5, legend_pos='right', is_geo_effect_show=True) # geo.render("Geo-Low.html") page.add(geo)
def plot_geo_station(re_dic, to_path): dw = my_(config.MYSQL_BI_RW_ENV) muchcols_table = 'data_center.dc_stations_muchcols_enc' sqls = "select name scale,latitude lat,longitude lng from %s where name like '%%%s%%'" % (muchcols_table, re_dic['name']) count_station_ = dw.to_dataframe(sqls) count_station_['numbers']=1 coords={} for i in range(len(count_station_)): coords[count_station_.loc[i,'scale']]=[count_station_.loc[i,'lng'],count_station_.loc[i,'lat']] # num_Max = count_station_['numbers'].max() name_str = "油站名包含'%s':" %re_dic['name'] if re_dic['name'] else '' page = pyecharts.Page() style = pyecharts.Style(width=1300, height=860, background_color='#404a49', title_color="#eee", title_pos="center") geo = pyecharts.Geo(name_str+"油站分布地图",**style.init_style) geo.add("",count_station_['scale'], count_station_['numbers'], visual_text_color="#eee", is_legend_show=False, symbol_size=11, is_visualmap=True, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right',geo_cities_coords=coords) page.add(geo) page.render(to_path)
def plot_city(friends): friends_city = [] for city in friends[1:]: friends_city.append(city['City']) city_loc = collections.Counter(friends_city) print(city_loc) values = [] for city in set(friends_city): if city != '' and city.isalpha() and city[0].isupper() == False: values.append((city, city_loc[city])) geo = pc.Geo(u"陈永斌 各省微信好友分布", 'John', title_color='#fff', title_pos='center', width=1200, height=600, background_color='#404a59') attr, value = geo.cast(values) print(value) print(attr) geo.add('', attr, value, visual_range=[0, 200], visual_text_color='#fff', symbol_size=15, is_visualmap=True) geo.show_config() geo.render('weixin2.html')
names=['id','city','comments','score','date','fileview','sex'] UniqueComments=pd.read_table('/home/monchu/Data/assignments/aquamanComments.txt','r',names=names,delimiter='\t') cityCounter=Counter() UniqueComments['city'].describe() after=pd.DataFrame() for index,row in UniqueComments.iterrows(): if row['date']>'2018-12-07 00:00:00': try: city=unicode(row['city'],'utf-8') cityCounter[city]+=1 #after=after.append(row) except:pass #after.to_csv('/home/monchu/Data/assignments/Valuable.csv',sep='\t',index=False) cityDict=dict(cityCounter) attr,value=pyecharts.Geo.cast(cityDict) geo= pyecharts.Geo("Distribution of Aquaman film commenters in China (Total comments:{})".format(sum(value)), "Data scraped from MaoYao.com; Before 2018-12-20 11:09:25", title_color="#fff", title_pos="center", width=1200, height=600,background_color='#404a59') geo.add_coordinate_json('/home/monchu/Data/assignments/city2.json') flag=True i=0 geo.add_coordinate(u'伊犁',80.9,91.01) geo.add_coordinate(u'杨凌',107.59,34.14) geo.add_coordinate(u'海东',102.12,36.50) geo.add_coordinate(u'海南州',99,36) geo.add_coordinate(u'璧山',106.15,29.41) geo.add_coordinate(u'锡林郭勒',116.23,43.23) while flag: try: geo.add("", attr, value,visual_range=[min(value),max(value)],is_piecewise=True,visual_text_color="#fff",symbol_size=6, is_visualmap=True,visual_split_numer=6) print "?" flag=False except Exception as e:
except: pass results = pd.DataFrame( results, columns=['cityName', 'content', 'gender', 'id', 'startTime']) print(results[:5]) results.to_csv('movie_duye_comments.txt', sep='\t', index=False) data = pd.read_csv('movie_duye_comments.txt', sep='\t', header=0, encoding='utf-8') print(data['content'][:5]) ##pic 1 distribution map geo = pyecharts.Geo(' distribution of duye ', 'data resource: maoyan') attr, value = geo.cast(list(data['content'])) # print(value) geo.add('', attr, value, visual_range=[0, 5000], visual_text_color='#fff', symbol_size=15, is_visualmap=True, is_piecewise=False, visual_split_number=10) geo.render('movie_duye_map.html') ##pic 2 city bar data_top20 = Counter(list(data['cityName'])).most_common(20)
['广州', '杭州'] ] ''' data_gz = [['广州', '上海'], ['广州', '杭州'], ['广州', '南京'], ['广州', '西安'], ['广州', '北京'], ['广州', '长沙'], ['广州', '重庆'], ['广州', '成都'], ['广州', '南昌'], ['广州', '贵阳'], ['广州', '昆明'], ['广州', '哈尔滨'], ['广州', '武汉'], ['广州', '兰州'], ['广州', '拉萨'], ['广州', '乌鲁木齐'], ['广州', '呼和浩特'], ['广州', '台北'], ['广州', '天津'], ['广州', '福州'], ['广州', '郑州'], ['广州', '太原'], ['广州', '长春'], ['广州', '济南'], ['广州', '银川'], ['广州', '南宁'], ['广州', '海口'], ['广州', '合肥'], ['广州', '石家庄'], ['广州', '沈阳']] geo = pca.Geo('GeoLines示例', **style.init_style) geo_lines = pca.GeoLines('GeoLines示例', **style.init_style) geo_lines.add('从广州出发', data_gz, is_legend_show=False) geo_lines.render(r'd:\render.html') from pyecharts import Geo import pyecharts as pca style = pca.Style(title_top='#fff', title_pos='center', width=1200, height=600, background_color='#404a59') data = [('广州', 45), ('漳州', 35), ('A市', 43)] geo = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
bar = echarts.Bar("Bar chart", "precipitation and evaporation one year") bar.add("precipitation", attr, v1, is_label_show=True, label_formatter=label_formatter) bar.render(path='tmp/formatter.html') # Tooltip tooltip_formatter if __name__ == '__main__': def geo_formatter(params): return params.name + ' : ' + params.value[2] data = [('澄海区', 30), ('南澳县', 40), ('龙湖区', 50), ('金平区', 60)] geo = echarts.Geo("汕头市地图示例", ) attr, value = geo.cast(data) geo.add( "", attr, value, maptype="汕头", is_visualmap=True, is_legend_show=False, tooltip_formatter=geo_formatter, # 重点在这里,将函数直接传递为参数。 label_emphasis_textsize=15, label_emphasis_pos='right', ) geo.render(path='tmp/formatter.html') # Label 示例
def aboutMe(request): gauge = pyecharts.Gauge('', background_color='#f5f5f5') gauge.add('title', 'Percent', 80.66, scale_range=[0, 100], is_more_utils=True) gauge.show_config() result = gauge.render_embed() data = [("宿迁", 9), ("武汉", 10), ("重庆", 12), ("哈尔滨", 18), ("乌鲁木齐", 10), ("北京", 15), ("南京", 13)] geo = pyecharts.Geo("中国各城市PM2.5含量示意图", "data from pm2.5", title_color="#000", title_pos="center", background_color='#f5f5f5') attr, value = geo.cast(data) geo.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5, is_more_utils=True) geo.show_config() result1 = geo.render_embed() attr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] v1 = [20, 33, 133, 124, 24, 313] v2 = [2.6, 12, 31, 241, 324, 134] bar = pyecharts.Bar('Bar Sample', background_color='#f5f5f5') bar.add("A", attr, v1, mark_line=["average"], mark_point=["min", "max"]) bar.add("B", attr, v2, mark_line=["average"], mark_point=["min", "max"], is_more_utils=True) bar_result = bar.render_embed() pie = pyecharts.Pie('', background_color="#f5f5f5") pie.add("", attr, v1, is_lable_show=True, lable_text_color="#156ACF", is_more_utils=True) pie.show_config() pie_result = pie.render_embed() liquid = pyecharts.Liquid('', background_color="#000") liquid.add("", [0.66, 0.5], ['diamond'], ['#294D99', '#156ACF'], is_more_utils=True) liquid.show_config() liquid_result = liquid.render_embed() l3d = line3d() l3d_result = l3d.render_embed() name = [ 'afaaf', 'Tom han', 'ajf oafoa', 'auoj aoudh', 'ad da fa', 'auohdahb da' ] value = [ 10000, 1132, 414, 1313, 3452, 1413, ] wordcloud = pyecharts.WordCloud(width=800, height=400, background_color="#000") wordcloud.add("", name, value, word_size_range=[20, 100], rotate_step=50) wordcloud.show_config() w = wordcloud.render_embed() REMOTE_HOST = "https://pyecharts.github.io/assets/js" return render_to_response( 'AboutMe.html', { 'result': result, 'result1': result1, 'bar_result': bar_result, 'pie_result': pie_result, 'liquid_result': liquid_result, 'l3d_result': l3d_result, 'host': REMOTE_HOST, 'script_list': l3d.get_js_dependencies(), 'w': w })