def my_Geolines(): style = Style(title_top="#fff", title_pos="center", width=1200, height=600, background_color="#404a59") style_geo = style.add( is_label_show=True, line_curve=0.2, line_opacity=0.6, legend_text_color="#eee", legend_pos="right", geo_effect_symbol="plane", geo_effect_symbolsize=15, label_color=['#a6c84c', '#ffa022', '#46bee9'], label_pos="right", label_formatter="{b}", label_text_color="#eee", ) data_guangzhou = [["珠海", "番禺区", 55], ["番禺区", "天河区", 6], ["天河区", "南昌", 259]] geolines = GeoLines("GeoLines 示例", **style.init_style) geolines.add("从广州出发", data_guangzhou, tooltip_formatter="{a} : {c}", **style_geo) geolines.render()
def ewide5(request): template = loader.get_template('ewpyecharts.html') style = Style(title_top="#fff", title_pos="center", width=1200, height=600, background_color="#404a59") style_geo = style.add( is_label_show=True, line_curve=0.2, line_opacity=0.6, legend_text_color="#eee", legend_pos="right", geo_effect_symbol="plane", geo_effect_symbolsize=15, label_color=['#a6c84c', '#ffa022', '#46bee9'], label_pos="right", label_formatter="{b}", label_text_color="#eee", ) data_guangzhou = [["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "重庆"], ["广州", "兰州"], ["广州", "杭州"]] data_beijing = [["北京", "上海"], ["北京", "广州"], ["北京", "南京"], ["北京", "重庆"], ["北京", "兰州"], ["北京", "杭州"]] geolines1 = GeoLines("GeoLines 示例", **style.init_style) geolines1.add("从广州出发", data_guangzhou, **style_geo) geolines1.add("从北京出发", data_beijing, **style_geo) # geo.show_config() context = dict(myechart=geolines1.render_embed(), host=REMOTE_HOST, script_list=geolines1.get_js_dependencies()) return HttpResponse(template.render(context, request))
def test_timeline_pie(): style = Style() pie_style = style.add( is_label_show=True, radius=[30, 55], rosetype="radius" ) pie_1 = Pie("2012 年销量比例", "数据纯属虚构") pie_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_2 = Pie("2013 年销量比例", "数据纯属虚构") pie_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_3 = Pie("2014 年销量比例", "数据纯属虚构") pie_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_4 = Pie("2015 年销量比例", "数据纯属虚构") pie_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_5 = Pie("2016 年销量比例", "数据纯属虚构") pie_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) timeline = Timeline(is_auto_play=True, timeline_bottom=0, width=1200, height=600) timeline.add(pie_1, '2012 年') timeline.add(pie_2, '2013 年') timeline.add(pie_3, '2014 年') timeline.add(pie_4, '2015 年') timeline.add(pie_5, '2016 年')
def test_style(): style = Style(title_pos="center") s1 = style.add(is_random=True, label_pos="top") assert style.init_style['title_pos'] == "center" assert style.init_style.get('title', None) is None assert s1['is_random'] is True assert s1['label_pos'] == "top"
def analysisProvince(): friends_info = get_friends_info() df = pd.DataFrame(friends_info) province_count = df.groupby( 'province', as_index=True)['province'].count().sort_values() temp = list( map(lambda x: x if x != '' else '未知', list(province_count.index))) # 画图 page = Page() style = Style(width=1100, height=600) style_middle = Style(width=900, height=500) attr, value = temp, list(province_count) chart1 = Map('好友分布(中国地图)', **style.init_style) chart1.add('', attr, value, is_label_show=True, is_visualmap=True, visual_text_color='#000') page.add(chart1) chart2 = Bar('好友分布柱状图', **style_middle.init_style) chart2.add('', attr, value, is_stack=True, is_convert=True, label_pos='inside', is_legend_show=True, is_label_show=True) page.add(chart2) page.render('analysisProvince.html')
def analysisCity(province): friends_info = get_friends_info() df = pd.DataFrame(friends_info) temp1 = df.query('province == "%s"' % province) city_count = temp1.groupby('city', as_index=True)['city'].count().sort_values() attr = list( map(lambda x: '%s市' % x if x != '' else '未知', list(city_count.index))) value = list(city_count) # 画图 page = Page() style = Style(width=1100, height=600) style_middle = Style(width=900, height=500) chart1 = Map('%s好友分布' % province, **style.init_style) chart1.add('', attr, value, maptype='%s' % province, is_label_show=True, is_visualmap=True, visual_text_color='#000') page.add(chart1) chart2 = Bar('%s好友分布柱状图' % province, **style_middle.init_style) chart2.add('', attr, value, is_stack=True, is_convert=True, label_pos='inside', is_label_show=True) page.add(chart2) page.render('analysisCity.html')
def test_timeline_pie(): style = Style() pie_style = style.add(is_label_show=True, radius=[30, 55], rosetype="radius") pie_1 = Pie("2012 年销量比例", "数据纯属虚构") pie_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_2 = Pie("2013 年销量比例", "数据纯属虚构") pie_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_3 = Pie("2014 年销量比例", "数据纯属虚构") pie_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_4 = Pie("2015 年销量比例", "数据纯属虚构") pie_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_5 = Pie("2016 年销量比例", "数据纯属虚构") pie_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) timeline = Timeline(is_auto_play=True, timeline_bottom=0, width=1200, height=600) timeline.add(pie_1, "2012 年") timeline.add(pie_2, "2013 年") timeline.add(pie_3, "2014 年") timeline.add(pie_4, "2015 年") timeline.add(pie_5, "2016 年") assert len(timeline._option.get("baseOption").get("series")) == 0 timeline.render()
def generate_3d_bar_chart(): data = pd.read_excel(input_file_path + '每日销量.xlsx', sheet_name=0) print(data.head()) x_axis = data['week'].tolist() data['week'] = data['week'].str.replace('week', '').map(int) - 1 data = data.set_index('week') y_axis = data.columns.tolist() data.columns = range(0, 7) data = data.stack().reset_index() data.columns = ['week', 'day', 'amount'] print(data.head()) style = Style( title_color='#A52A2A', title_pos='center', width=900, height=1100, background_color='#ABABAB' ) style_3d = style.add( is_visualmap=True, visual_range=[0, 120], visual_range_color=['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'], grid3d_width=200, grid3d_depth=80, xaxis_label_textcolor='#fff', is_grid3d_rotate=True, legend_pos='right' ) bar3d = Bar3D('全年产量情况', **style.init_style) bar3d.add('每日产量', x_axis, y_axis, data.values.tolist(), **style_3d) bar3d.render(output_file_path + 'htmls/全年产量情况3D柱状图.html')
def create_charts(): users = get_friends() page = Page() style = Style(width=1100, height=600) style_middle = Style(width=900, height=500) data = sex_stats(users) attr, value = data chart = Pie('微信性别') # title_pos='center' chart.add('', attr, value, center=[50, 50], radius=[30, 70], is_label_show=True, legend_orient='horizontal', legend_pos='center', legend_top='bottom', is_area_show=True) page.add(chart) data = prov_stats(users) attr, value = data chart = Map('中国地图', **style.init_style) chart.add('', attr, value, is_label_show=True, is_visualmap=True, visual_text_color='#000') page.add(chart) chart = Bar('柱状图', **style_middle.init_style) chart.add('', attr, value, is_stack=True, is_convert=True, label_pos='inside', is_legend_show=True, is_label_show=True) page.add(chart) data = gd_stats(users) attr, value = data chart = Map('河南', **style.init_style) chart.add('', attr, value, maptype='河南', is_label_show=True, is_visualmap=True, visual_text_color='#000') page.add(chart) chart = Bar('柱状图', **style_middle.init_style) chart.add('', attr, value, is_stack=True, is_convert=True, label_pos='inside', is_label_show=True) page.add(chart) page.render()
def test_timeline_pie(): style = Style() pie_style = style.add( is_label_show=True, radius=[30, 55], rosetype="radius" ) pie_1 = Pie("2012 年销量比例", "数据纯属虚构") pie_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_2 = Pie("2013 年销量比例", "数据纯属虚构") pie_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_3 = Pie("2014 年销量比例", "数据纯属虚构") pie_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_4 = Pie("2015 年销量比例", "数据纯属虚构") pie_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_5 = Pie("2016 年销量比例", "数据纯属虚构") pie_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) timeline = Timeline( is_auto_play=True, timeline_bottom=0, width=1200, height=600 ) timeline.add(pie_1, "2012 年") timeline.add(pie_2, "2013 年") timeline.add(pie_3, "2014 年") timeline.add(pie_4, "2015 年") timeline.add(pie_5, "2016 年") assert len(timeline.options.get("baseOption").get("series")) == 0 timeline.render()
def escape(self): echart_unsupported_city = [ "菏泽市", "襄阳市", "恩施州", "湘西州","阿坝州", "延边州", "甘孜州", "凉山州", "黔西南州", "黔东南州", "黔南州", "普洱市", "楚雄州", "红河州", "文山州", "西双版纳州", "大理州", "德宏州", "怒江州", "迪庆州", "昌都市", "山南市", "林芝市", "临夏州", "甘南州", "海北州", "黄南州", "海南州", "果洛州", "玉树州", "海西州", "昌吉州", "博州", "克州", "伊犁哈萨克州"] 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 for index, row in df_aqi.iterrows(): city = row['city'] aqi = row['aqi'] if city in echart_unsupported_city: continue if aqi < localAQI and aqi<20 : data.append( ['长沙',city] ) global lastcity lastcity=city style = Style( title_top="#fff", title_pos = "center", title_color="#fff", width=425, height=730, background_color="#404a59" ) style_geo = style.add( is_label_show=True, line_curve=0.2,#线条曲度 line_opacity=0.6, legend_text_color="#fff",#图例文字颜色 legend_pos="right",#图例位置 geo_effect_symbol="plane",#特效形状 geo_effect_symbolsize=15,#特效大小 label_color=['#a6c84c', '#ffa022', '#46bee9'], label_pos="right", label_formatter="{b}",#//标签内容格式器 label_text_color="#fff", ) print(data) print(lastcity) geolines = GeoLines("逃离路线", **style.init_style) geolines.add("出发", data, **style_geo) geolines.render('aqi.html') self.webView.load(QUrl("file:///D:/源代码/aqi.html")) #self.webView.reload() self.webView.repaint() self.webView.update()
def plot_geolines(plotting_data, geo_cities_coords): # 设置画布的格式 style = Style(title_pos="center", width=1000, height=800) # 部分地理轨迹图的格式 style_geolines = style.add( is_label_show=True, line_curve=0.3, # 轨迹线的弯曲度,0-1 line_opacity=0.6, # 轨迹线的透明度,0-1 geo_effect_symbol='plane', # 特效的图形,有circle,plane,pin等等 geo_effect_symbolsize=10, # 特效图形的大小 geo_effect_color='#7FFFD4', # 特效的颜色 geo_effect_traillength=0.1, # 特效图形的拖尾效果,0-1 label_color=['#FFA500', '#FFF68F'], # 轨迹线的颜色,标签点的颜色, border_color='#97FFFF', # 边界的颜色 geo_normal_color='#36648B', # 地图的颜色 label_formatter='{b}', # 标签格式 legend_pos='left') # 作图 geolines = GeoLines('出行轨迹图', **style.init_style) geolines.add( '从北京出发', plotting_data, maptype='china', # 地图的类型,可以是省的地方,如'广东',也可以是地市,如'东莞'等等 geo_cities_coords=geo_cities_coords, **style_geolines) # 发布,得到图形的html文件 geolines.render()
def test_timeline_pie(): style = Style() pie_style = style.add( is_label_show=True, radius=[30, 55], rosetype="radius" ) pie_1 = Pie("2012 年销量比例", "数据纯属虚构") pie_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_2 = Pie("2013 年销量比例", "数据纯属虚构") pie_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_3 = Pie("2014 年销量比例", "数据纯属虚构") pie_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_4 = Pie("2015 年销量比例", "数据纯属虚构") pie_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) pie_5 = Pie("2016 年销量比例", "数据纯属虚构") pie_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style) timeline = Timeline(is_auto_play=True, timeline_bottom=0, width=1200, height=600) timeline.add(pie_1, '2012 年') timeline.add(pie_2, '2013 年') timeline.add(pie_3, '2014 年') timeline.add(pie_4, '2015 年') timeline.add(pie_5, '2016 年') timeline.render()
def Pie(): from pyecharts import Pie,Style def cut(value): if '中国' in value: return '中国' else: value = value.split(',')[0] return value file['areas'] = file['areas'].apply(cut) attr = file['areas'].value_counts().index.tolist() valu = file['areas'].value_counts().tolist() style = Style( title_pos = 'center', title_top = 'bottom', width = 900, height = 500, background_color = 'white') pie_style = style.add( legend_pos = 'center', #radius=[40, 75], label_color = [], label_text_color ='', is_label_show=True,#显示图例 数据 ) pie = Pie("areas:","",**style.init_style) pie.add("",attr,valu,**pie_style) pie.render('pie.html')
def Bar(): from pyecharts import Bar,Style def cut(value): if '中国' in value: return '中国' else: value = value.split(',')[0] return value file['areas'] = file['areas'].apply(cut) attr = file['areas'].value_counts().index.tolist() valu = file['areas'].value_counts().tolist() style = Style( title_pos = 'center', width = 900, height = 500, background_color = 'white') bar_style = style.add( legend_pos = 'bottom', label_color = ['yellow'], label_text_color ='blue', is_label_show=None,#显示图例 数据 mark_point=['max'], mark_line=['average']) bar = Bar("地区分布:","",**style.init_style)#标题和副标题 bar.add("",attr,valu,**bar_style) #is_convert = True 换x y轴 bar.render('bar.html')
def test_pie_multiple_movie(): pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center') style = Style() pie_style = style.add( label_pos="center", is_label_show=True, label_text_color=None ) pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], **pie_style) pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], **pie_style) pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], **pie_style) pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], **pie_style) pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], **pie_style) pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], **pie_style) pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], **pie_style) pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], **pie_style) pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], **pie_style) pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24], legend_top="center", **pie_style) pie.render()
def plot_upstream(self,outputname): self.init_dict_trans_isvisit() style = Style( title_color="#fff", title_pos="center", width=1510, height=840, background_color="#404a59" # #404a59" ) style_geo = style.add( maptype="china", is_label_show=False, line_curve=0.1, line_opacity=0.6, legend_text_color="#eee", legend_pos="right", geo_effect_symbol="arrow", symbol_size=5, geo_effect_symbolsize=5, label_color=['#a6c84c', '#46bee9','red'], label_pos="right", label_formatter="{b}", label_text_color="#eee", ) geolines = GeoLines(outputname, **style.init_style) geolines.add(name = "轻度",data = self.prop_df[self.prop_df['class']=='轻度'][['Source','Target']].values.tolist(), is_legend_show=False,**style_geo) geolines.add(name = "中度",data = self.prop_df[self.prop_df['class']=='中度'][['Source','Target']].values.tolist(), is_legend_show=True,**style_geo) geolines.add(name = "重度",data = self.prop_df[self.prop_df['class']=='重度'][['Source','Target']].values.tolist(), is_legend_show=True,**style_geo) geolines.render(outputname+'.html')
def test_style(): style = Style(title_pos="center") s1 = style.add(is_random=True, label_pos="top") assert style.init_style["title_pos"] == "center" assert style.init_style.get("title", None) is None assert s1["is_random"] is True assert s1["label_pos"] == "top"
def data_visualization(login_success_value=0, login_failure_value=0, shiming_success_value=0, shiming_failure_value=0, fangyuan_success_value=0, fangyuan_failure_value=0, mensuo_success_value=0, mensuo_failure_value=0): ''' 数据可视化,连环拼图 :param login_success_value: :param login_failure_value: :param shiming_success_value: :param shiming_failure_value: :param fangyuan_success_value: :param fangyuan_failure_value: :param mensuo_success_value: :param mensuo_failure_value: :return: ''' pie = Pie('Results of each interface test', 'Data to Jenkins', title_pos='center') style = Style() pie_style = style.add(label_pos="center", is_label_show=True, label_text_color='#6E6E6E') pie.add('', ['Login Success', 'Login Failure'], [login_success_value, login_failure_value], center=[10, 30], radius=[20, 30], **pie_style) pie.add('', ['ShiMing Success', 'ShiMing Failure'], [shiming_success_value, shiming_failure_value], center=[10, 80], radius=[20, 30], **pie_style) pie.add('', ['FangYuan Suceess', 'FangYuan Failure'], [fangyuan_success_value, fangyuan_failure_value], center=[40, 30], radius=[20, 30], **pie_style) pie.add('', ['MenSuo Success', 'MenSuo Failure'], [mensuo_success_value, mensuo_failure_value], center=[40, 80], radius=[20, 30], legend_top="center", **pie_style) pie.show_config() pie.render(filename)
def draw_dif_faculty_sex_pie_chart(self, df: pd.DataFrame): """ 各学院男女借书比例 :param df: :return: """ male = df['Male'].tolist() female = df['Female'].tolist() faculty_list = df['Faculty'].tolist() faculty_sex_list = list(zip(male, female, faculty_list)) pie = Pie(title='广商各学院借书男女人数比', subtitle="男女人数比", title_pos='center', **self.style.init_style) style = Style() pie_style = style.add( label_pos="center", is_label_show=True, label_text_color="#698B69", label_emphasis_textcolor="#9dccfb", label_emphasis_pos="center", legend_top="center", label_color=['#4876FF', '#EE3B3B'] ) label_list = ["男", "女"] pie.add("", label_list, list(faculty_sex_list[0][:-1]), center=[10, 30], radius=[18, 24], label_formatter=faculty_sex_list[0][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[1][:-1]), center=[30, 30], radius=[18, 24], label_formatter=faculty_sex_list[1][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[2][:-1]), center=[50, 30], radius=[18, 24], label_formatter=faculty_sex_list[2][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[3][:-1]), center=[70, 30], radius=[18, 24], label_formatter=faculty_sex_list[3][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[4][:-1]), center=[90, 30], radius=[18, 24], label_formatter=faculty_sex_list[4][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[5][:-1]), center=[10, 70], radius=[18, 24], label_formatter=faculty_sex_list[5][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[6][:-1]), center=[30, 70], radius=[18, 24], label_formatter=faculty_sex_list[6][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[7][:-1]), center=[50, 70], radius=[18, 24], label_formatter=faculty_sex_list[7][-1] + "\n{b}: {d}%\n", **pie_style) pie.add("", label_list, list(faculty_sex_list[8][:-1]), center=[70, 70], radius=[18, 24], label_formatter=faculty_sex_list[8][-1] + "\n{b}: {d}%\n", **pie_style) if self._json_mode: return pie.options else: self._public_page_render(chart=pie, filename="广商各学院借书男女人数比")
def dashboard(): '''仪表盘''' gauge = Gauge('Results of each interface test') style = Style() gauge_style = style.add(label_pos='center', is_label_show=True, label_text_color=None) gauge.add('Login Interface Test', 'Rate of passing', 70, **gauge_style) #gauge.add('FangYuan Interface Test','Rate of passing',60,**gauge_style) gauge.show_config() gauge.render(filename)
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 create_charts(): page = Page() style = Style(width=900, height=600, title_pos='center') w = '雷音' res = {} for rt, ds, ffs in os.walk('/Users/fxm/经语料/T_out/'): for d in ds: if int(d.replace('T', '')) < 18: for rr, dd, ff in os.walk(rt + d): for f in ff: with open(rr + '/' + f, encoding='utf8') as file: ss = file.read() jm = re.search('title:(.*)\s', ss).group(1) try: res[jm] += ss.count(w) except: res[jm] = ss.count(w) res = sorted(res.items(), key=lambda x: x[1], reverse=True)[:50] attr = [x[0] for x in res] v1 = [x[1] for x in res] chart = Bar("雷音-經目出現頻次圖", **style.init_style) # chart.add("", attr, v1, xaxis_interval=0, xaxis_rotate=30,yaxis_rotate=30) chart.add("", attr, v1, is_label_show=True, is_datazoom_show=True, xaxis_rotate=30, xaxis_interval=0) page.add(chart) return page
def create_charts_pie(): #pie page = Page() style = Style(width=1100, height=900) data = pd.read_csv( '/Users/fxm/PycharmProjects/fo/data/结果/名+标点_class_1213.csv') ks1, vs1 = [], [] for k, v in countit(data['d'].values).items(): ks1.append(k) vs1.append(v) ks2, vs2 = [], [] for k, v in countit(data['e'].values).items(): ks2.append(k) vs2.append(v) chart = Pie("类别分布", title_pos='center', **style.init_style) chart.add("", ks2, vs2, radius=[60, 80], is_label_show=True, is_legend_show=False) chart.add("", ks1, vs1, radius=[0, 50], is_label_show=True, is_legend_show=False, label_pos='inside') page.add(chart) return page
def create_line(title, line_data, show_avg=True, attr=None): # 横竖坐标的大小 style = Style(width=800, height=600) chart = Line(title, **style.init_style) if len(line_data) == 0: return if attr is None: attr = [] size = len(line_data[0].dataList) for i in range(1, size + 1): cur = u"第 " + str(i) + u" 次" attr.append(cur) for data in line_data: if show_avg is True: chart.add(data.phone_type, attr, data.dataList, is_label_show=True, mark_line=["average"]) else: chart.add(data.phone_type, attr, data.dataList, is_label_show=True) return chart
def create_charts(data): # data字典格式(三个表的情况下): # {'charcloud':[str:表一的前描述,str:表一的后描述,数据1,数据2,...,数据n],'...':[...]} html = '' page = Page() style = Style(width=900, height=600) # 本页面包含:1:所有字的词云charcloud(两个数据chars,values)、 # 表一: # 获取表一的数据 html_before = data['charcloud'][0] html_after = data['charcloud'][1] chars = data['charcloud'][2] values = data['charcloud'][3] wordcloud = WordCloud("唐诗用字云图", **style.init_style) wordcloud.add("字云", chars, values, word_size_range=[10, 100], shape='pentagon') java_script = wordcloud.render_embed() html += html_before + java_script + html_after page.add(wordcloud) # 表二: html_before = data['chartop10'][0] html_after = data['chartop10'][1] chars = data['chartop10'][2] values = data['chartop10'][3] bar = Bar("唐诗高频十字", **style.init_style) bar.add("柱状图", chars, values) java_script = bar.render_embed() html += html_before + java_script + html_after page.add(bar) # 表三: html_before = data['frequency×'][0] html_after = data['frequency×'][1] keys = data['frequency×'][2] values = data['frequency×'][3] line = Line("唐诗字频-字数", **style.init_style) line.add("字频--字数", keys, values, is_smooth=True, is_fill=True, area_opacity=0.2, is_datazoom_show=True, datazoom_type="both", datazoom_range=[0, 60], xaxis_interval=1, yaxis_formatter="字", xaxis_name="频次", yaxis_name="字数", xaxis_name_pos="end", yaxis_name_pos="end", is_more_utils=True) java_script = line.render_embed() html += html_before + java_script + html_after page.add(line) # 最后 script = page.get_js_dependencies() return html, script
def create_charts(): page = Page() style = Style(width=WIDTH, height=HEIGHT) attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] chart = Funnel("漏斗图示例", **style.init_style) chart.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff") page.add(chart) chart = Funnel("漏斗图示例", title_pos='center', **style.init_style) chart.add("商品", attr, value, is_label_show=True, label_pos="outside", legend_orient='vertical', legend_pos='left') page.add(chart) return page
def ewide2(request): template = loader.get_template('ewpyecharts.html') style = Style( title_top="#fff", title_pos="center", width=1200, height=600, background_color="#404a59" ) data_guangzhou = [ ["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "重庆"], ["广州", "兰州"], ["广州", "杭州"] ] geolines = GeoLines("水务地图可视化--点线图", **style.init_style) geolines.add("从广州出发", data_guangzhou, is_legend_show=False) context = dict( myechart=geolines.render_embed(), host=REMOTE_HOST, script_list=geolines.get_js_dependencies() ) return HttpResponse(template.render(context, request))
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 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 line_ssdd(attr_v1_v2: List[Tuple[str, int, int]], chart_name: str, v1_name: str, v2_name: str) -> line.Line: """ 生成一个折线图-数据堆叠图 :param attr_v1_v2: 包含想要显示的数据列表 :param chart_name: 图表名 :param v1_name: 数据一名 :param v2_name: 数据二名 """ style = Style(width=WIDTH, height=HEIGHT) attr = [a[0] for a in attr_v1_v2] v1 = [v[1] for v in attr_v1_v2] v2 = [v[2] for v in attr_v1_v2] # chart = Line(chart_name, **style.init_style) # chart.add(v1_name, attr, v1, is_label_show=True, is_smooth=True) # chart.add(v2_name, attr, v2, is_label_show=True, is_smooth=True) chart = Line(chart_name, **style.init_style) chart.add(v1_name, attr, v1, mark_point=["average"]) chart.add(v2_name, attr, v2, is_smooth=True, mark_line=["max", "average"], is_more_utils=True) return chart
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 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 get_style(self, axis, **kwargs): pos = self._axis_num[axis] num = self._num style = Style() default_datazoom_type = 'both' result = None if num == 1: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type) elif num == 2: if pos == 0: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1], is_xaxis_show=False) else: result = style.add(legend_text_size='10', legend_top='62%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1], is_xaxis_show=True) elif num == 3: if pos == 0: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2], is_xaxis_show=False) elif pos == 1: result = style.add(legend_text_size='10', legend_top='50%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2], is_xaxis_show=False) else: result = style.add(legend_text_size='10', legend_top='71%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2], is_xaxis_show=True) else: if pos == 0: result = style.add(legend_text_size='10', legend_top='8%', legend_pos='10%', legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=False) elif pos == 1: result = style.add(legend_text_size='10', legend_top='40%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=False) elif pos == 2: result = style.add(legend_text_size='10', legend_top='60%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=False) else: result = style.add(legend_text_size='10', legend_top='77%', legend_pos='10%', #legend_orient='vertical', is_symbol_show=False, is_datazoom_show=True, datazoom_type=default_datazoom_type, datazoom_xaxis_index=[0,1,2,3], is_xaxis_show=True) color_map = {'r': '#CD0000', 'g': '#008B00', 'b': '#0000EE', 'c':'#40E0D0', 'm': '#CD00CD', 'y': '#EE9A00', 'k': '#000000', 'w': '#FFFFFF' } line_map = {'-' : 'solid', '--': 'dashed', ':' : 'dotted'} for item in kwargs.items(): if 'color' == item[0]: color = color_map[item[1]] if item[1] in color_map else color_map['r'] result['line_color'] = color self._label_color += [color] result['label_color'] = self._label_color elif 'linestyle' == item[0]: result['line_type'] = line_map[item[1]] if item[1] in line_map else line_map['-'] else: result[item[0]] = item[1] return result
#!/usr/bin/env python # coding=utf-8 from __future__ import unicode_literals from nose.tools import assert_raises from pyecharts import GeoLines, Style from pyecharts.datasets.coordinates import search_coordinates_by_keyword style = Style( title_top="#fff", title_pos="center", width=1200, height=600, background_color="#404a59", ) style_geo = style.add( is_label_show=True, line_curve=0.2, line_opacity=0.6, legend_text_color="#eee", legend_pos="right", geo_effect_symbol="plane", geo_effect_symbolsize=15, label_color=["#a6c84c", "#ffa022", "#46bee9"], label_pos="right", label_formatter="{b}", label_text_color="#eee", legend_selectedmode="single", )