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 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 年') 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 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 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 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 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 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_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 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 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 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 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 GuanJianCi(self, data_name="None", num=20, text=None): page = Page() if text == None: text = "SimHash是一种局部敏感hash,它也是Google公司进行海量网页去重使用的主要算法。传统的Hash算法只负责将原始内容尽量均匀随机地映射为一个签名值,原理上仅相当于伪随机数产生算法。传统的hash算法产生的两个签名,如果原始内容在一定概率下是相等的;如果不相等,除了说明原始内容不相等外,不再提供任何信息,因为即使原始内容只相差一个字节,所产生的签名也很可能差别很大。所以传统的Hash是无法在签名的维度上来衡量原内容的相似度,而SimHash本身属于一种局部敏感哈希算法,它产生的hash签名在一定程度上可以表征原内容的相似度。我们主要解决的是文本相似度计算,要比较的是两个文章是否相似,当然我们降维生成了hash签名也用于这个目的。看到这里估计大家就明白了,我们使用的simhash就算把文章中的字符串变成 01 串也还是可以用于计算相似度的,而传统的hash却不行。" tags = jieba.analyse.extract_tags(text, topK=num, withWeight=True, withFlag=True) name = [] value = [] for tag in tags: name.append(tag[0]) value.append(tag[1]) print(value) wordCloud = WordCloud(data_name) wordCloud.add("", name, value) pie = Pie('前十个词汇占重', "", title_pos='center') style = Style() pie_style = style.add(label_pos="center", is_label_show=True, label_text_color=None) hight = 10 width = 30 sum_Wight = sum(value) for index, (n, v) in enumerate(zip(name, value)): if index == 5: hight = 10 width = width + 40 if index < 10: pie.add("", [n, ""], [v / sum_Wight, 1 - v / sum_Wight], center=[hight, width], radius=[18, 24], **pie_style) hight = hight + 20 print(hight, width) print index page.add(pie) page.add(wordCloud) save_helper.save_tu_helper(page, data_name)
def single_chart_common(**kwargs): """ :param kwargs: 该类支持 Line(折线图), Bar(柱状图), Gauge(仪表盘), 主要看当个指标的完成率等 Pie(饼图), Scatter(散点图) 相关性分析,聚类分析 WordCloud(词云图) 热点词分析 Map(地图) Funnel(漏斗图): 展示数据变化的一个逻辑流程转化 EffectScatter(涟漪特效动画散点图):利用动画特效可以将某些想要突出的数据进行视觉突出 :return: """ n_fields, column_conf = field_get(**kwargs) charts_conf = kwargs.get("echarts", {}) style = Style(**charts_conf.get("init_style")) title = charts_conf.get("title") x_conf = column_conf.pop("x") x_value = x_conf.get('value') for field in column_conf.keys(): y_conf = column_conf.get(field) y_value = y_conf.pop('value') max_value = heapq.nlargest(1, y_value)[0] min_value = heapq.nsmallest(1, y_value)[0] chart_type = y_conf.pop('chart_type') field_nm = y_conf.pop('name') data_chart = getattr(pyecharts, chart_type)(title=title, **style.init_style) if chart_type == 'Map': y_conf["visual_range"] = [min_value, max_value] if len(y_value) == 1: y_value = y_value[0] data_chart.add(field_nm, x_value, y_value, **style.add(**y_conf)) return data_chart
def gen_render_html( nodes_path, edges_path, output_path=r'../results/energy/figure/2015-2017-finished/city_coop.html' ): # 读取节点和边 nodes = pd.read_csv(nodes_path, delimiter=';') edges = pd.read_csv(edges_path, delimiter=';') # 设置生成echarts地理流向图的配置 geocode = { nodes.iloc[i]['name']: [nodes.iloc[i]['Longitude'], nodes.iloc[i]['Latitude']] for i in range(len(nodes)) } style = Style(title_color="#fff", title_pos="center", width=2400, height=1200, background_color="white") edge_data = [[ edges.iloc[i]['source'], edges.iloc[i]['target'], edges.iloc[i]['weight'] ] for i in range(len(edges))] style_geo = style.add(line_opacity=0.2, line_color='#2980b9') # 渲染 geolines = GeoLines('城市合作网络', **style.init_style) geolines.add("", edge_data, maptype='world', geo_cities_coords=geocode, is_geo_effect_show=False, is_roam=False, symbol_size=0, geo_normal_color='#dcdcdc', border_color='black', **style_geo) os.makedirs(os.path.dirname(output_path), exist_ok=True) geolines.render(output_path) return
def geolines(): """地理坐标系线图""" data_beijing = [["北京", "上海"], ["北京", "广州"], ["北京", "南京"], ["北京", "重庆"], ["北京", "兰州"], ["北京", "杭州"]] data_guangzhou = [ ["广州", "上海", 10], ["广州", "北京", 20], ["广州", "南京", 30], ["广州", "重庆", 40], ["广州", "兰州", 50], ["广州", "杭州", 60], ] data_shanghai = [ ["上海", "广州", 10], ["上海", "北京", 20], ["上海", "南京", 30], ["上海", "重庆", 40], ["上海", "兰州", 50], ["上海", "杭州", 60], ] style = Style(title_top="#fff", title_pos="center", width=1200, height=800, 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", ) geolines = GeoLines("地理坐标系线图", **style.init_style) geolines.add("从广州出发", data_guangzhou, **style_geo) geolines.add("从北京出发", data_beijing, **style_geo) geolines.add("从上海出发", data_shanghai, **style_geo) geolines.render("地理坐标系线图.html")
def geolines(): data_beijing = [["北京", "上海"], ["北京", "广州"], ["北京", "南京"], ["北京", "重庆"], ["北京", "兰州"], ["北京", "杭州"]] data_guangzhou = [ ["广州", "上海", 10], ["广州", "北京", 20], ["广州", "南京", 30], ["广州", "重庆", 40], ["广州", "兰州", 50], ["广州", "杭州", 60], ] 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", ) geolines = GeoLines("GeoLines", **style.init_style) geolines.add("从广州出发", data_guangzhou, **style_geo) geolines.add("从北京出发", data_beijing, **style_geo) # geolines.render() return render_template( 'geolines.html', geolines=geolines.render_embed(), host=REMOTE_HOST, script_list=geolines.get_js_dependencies(), )
def Pies_1(): attr = file.types.value_counts().index.tolist()[0:9] valu = file.types.value_counts().tolist()[0:9] 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='', #legend_orient="vertical", is_label_show=True, #显示图例 数据 ) pie = Pie("", "", **style.init_style) pie.add("", attr, valu, **pie_style) pie.render('./Echarts/pie.html')
def Bars(): attr = file.areas.value_counts().index.tolist()[0:7] valu = file.areas.value_counts().tolist()[0:7] style = Style( title_pos='left', width=1200, 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', 'min'], mark_line=['average']) bar = Bar("地区分布:", "", **style.init_style) #标题和副标题 bar.add("", attr, valu, **bar_style) #is_convert = True 换x y轴 bar.render('./Echarts/bar.html')
def generate_kfc_dks_distribute_bar_chart(): """ 生成肯德基、德克士分布图 :return: """ # 读取数据 data = pd.read_excel(input_file_path + '省会城市KFC_MC_德克士.xlsx', sheet_name=0) print(data.head()) city = data['城市'].tolist() mc_num = data['麦当劳店面数量'].tolist() kfc_num = data['KFC店面数量'].tolist() dks_num = data['德克士店面数量'].tolist() # 设置样式 style = Style(title_pos='center', width=1000, height=500, background_color='white') bar_style = style.add(legend_top='bottom', # 图例位置 yaxis_rotate=45, # Y轴标签旋转角度 label_color=[' #FFB90F', '#FFF68F', '#1E90FF']) # 柱状图颜色 bar = Bar('省会城市快餐店数量', **style.init_style) bar.add('麦当劳', city, mc_num, is_stack=True, is_convert=False, **bar_style) # 是否堆积,是否反转 bar.add('肯德基', city, kfc_num, is_stack=True, is_convert=False, **bar_style) # 是否堆积,是否反转 bar.add('德克士', city, dks_num, is_stack=True, is_convert=False, **bar_style) # 是否堆积,是否反转 bar.render(output_file_path + 'htmls/省会城市快餐店数量堆积柱状图.html')
def plot_bfs(self, outputname, source_city='上海市', k=5, minimum=300): import json dict_nn = self.bfs(source_city, k, minimum=minimum) jsonstr = json.dumps(dict_nn) filename = open(outputname+'.json', 'w') # dict转josn filename.write(jsonstr) 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', '#ffa022','green'],#'#a6c84c' label_pos="right", label_formatter="{b}", label_text_color="#eee", # geo_cities_coords=airports_geo ) geolines = GeoLines(outputname, **style.init_style) for i in range(1,k+1): geolines.add(name=str(i)+"阶", data=dict_nn[i], is_legend_show=True, **style_geo) geolines.render(outputname+'近邻城市.html') return dict_nn
def Bar_x_y(): attr_1 = file.areas.value_counts().index.tolist()[0:7] attr_2 = file.types.value_counts().index.tolist()[0:3] datas = file[(file.areas.isin(attr_1)) & (file.types.isin(attr_2))] data = datas.groupby(['areas', 'types']).agg({'score': 'mean'}) data.score = data.score.round(decimals=1) list_1 = [] list_2 = [] list_3 = [] attr = attr_1 #print(city) #print(data.score.tolist()) for i in range(0, 7): list_1.append(data.score.tolist()[0 + 3 * i]) list_2.append(data.score.tolist()[1 + 3 * i]) list_3.append(data.score.tolist()[2 + 3 * i]) style = Style( title_pos='center', width=800, height=500, background_color='white', ) bar_style = style.add( legend_top='bottom', yaxis_rotate=45, is_label_show=None, label_color=['#FFB90F', '#FFF68F', '#1E90FF'], ) #print(city) print(list_1) bar = Bar('', **style.init_style) bar.add('剧情', attr, list_1, is_stack=True, **bar_style) #is_stack=True堆叠 bar.add('喜剧', attr, list_2, is_stack=True, **bar_style) bar.add('动作', attr, list_3, is_stack=True, **bar_style) bar.render('Echarts/bar_x_y.html')
def test3(): 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 = [["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "重庆"], ["广州", "兰州"], ["广州", "杭州"]] geolines = GeoLines("GeoLines 示例", **style.init_style) geolines.add("从广州出发", data_guangzhou, **style_geo) geolines.render("coordinate.html")
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
from pyecharts import GeoLines, Style 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, lengend_text_color='#eee', lengend_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", ) data_guangzhou = [["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "重庆"], ["广州", "兰州"], ["广州", "杭州"]] data_beijing = [["北京", "上海"], ["北京", "广州"], ["北京", "南京"], ["北京", "重庆"], ["北京", "兰州"], ["北京", "杭州"]] geolines = GeoLines("GeoLines 示例", **style.init_style) geolines.add("从广州出发", data_guangzhou, **style_geo,
from pyecharts import Geo, Style style = Style(title_top="#fff", title_pos="left", width=1000, height=800, background_color="#404a59") data = [['北京', '阿拉善左旗'], ['北京', '阿克苏'], ['北京', '安顺'], ['北京', '鞍山'], ['北京', '包头'], ['北京', '白城'], ['北京', '毕节'], ['北京', '保山'], ['北京', '巴彦淖尔'], ['北京', '松原'], ['北京', '深圳'], ['北京', '三亚'], ['北京', '上海'], ['北京', '十堰']] style_geo = style.add( is_label_show=True, line_curve=0.2, #曲线的弯曲度 line_opacity=0.5, #航线的透明度 legend_text_color="#eee", legend_pos="right", #示例的位置 geo_effect_symbol="plane", geo_effect_symbolsize=10, #飞机大小 label_color=['#ffa022', '#ffa022', '#46bee9'], label_pos="right", label_formatter="{b}", #地方标签的格式 label_text_color="#eee", ) geolines = Geo("GeoLines 示例", **style.init_style) #相当于设置背景 geolines.add("从北京出发", data, tooltip_formatter="{a} : {c}", **style_geo) geolines.render("F:/Python-study-diary/pyechartsss/airport1.html")
title_top="#fff", title_pos = "center", width=1200, height=600, background_color="#404a59" ) style_geo = style.add( is_label_show=False, symbol=['arrow', 'arrow'], symbol_size=1, line_width=3, line_curve=0.2, line_opacity=0.6, # legend_text_color="#eee", legend_pos="center", geo_effect_symbol="arrow", geo_effect_symbolsize=5, label_color=['#B9D3EE', '#C5C1AA', '#DB7093', '#B4EEB4', '#CD8162', '#FFEC8B', '#CD96CD'], label_pos="right", label_formatter="{b}", label_text_color="#00CDCD", item_color='#CD5C5C', legend_text_color='#CD5C5C' ) def create_charts(data): style = Style(width=900, height=900) page = Page() html='' charts = GeoLines("丝绸之路", **style.init_style)
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) for item in kwargs.items(): if 'color' == item[0]: color_map = {'r': '#CD0000', 'g': '#008B00', 'b': '#0000EE', 'c':'#40E0D0', 'm': '#CD00CD', 'y': '#EE9A00', 'k': '#000000', 'w': '#FFFFFF' } result['line_color'] = color_map[item[1]] if item[1] in color_map else color_map['r'] elif 'linestyle' == item[0]: line_map = {'-' : 'solid', '--': 'dashed', ':' : 'dotted'} result['line_type'] = line_map[item[1]] if item[1] in line_map else line_map['-'] else: result[item[0]] = item[1] return result
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", ) def test_geolines(): data_guangzhou = [ ["广州", "上海"], ["广州", "北京"], ["广州", "南京"], ["广州", "重庆"], ["广州", "兰州"],