def test_pie_type_rose(): v1 = [11, 12, 13, 10, 10, 10] v2 = [19, 21, 32, 20, 20, 33] pie = Pie("饼图-玫瑰图示例", title_pos="center", width=900) pie.add( "商品A", CLOTHES, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype="radius", ) pie.add( "商品B", CLOTHES, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype="area", is_legend_show=False, is_label_show=True, ) pie.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 test_pie_type_radius(): pie = Pie("饼图示例", title_pos='center', width=1000, height=600) pie.add("", ['A', 'B', 'C', 'D', 'E', 'F'], [335, 321, 234, 135, 251, 148], radius=[40, 55], is_label_show=True) pie.add("", ['H', 'I', 'J'], [335, 679, 204], radius=[0, 30], legend_orient='vertical', legend_pos='left') pie.render()
def get_pie(item_name,item_name_list,item_num_list): totle = item_num_list[0]+item_num_list[1]+item_num_list[2] subtitle = "共有:%d个好友"%totle pie = Pie(item_name,page_title = item_name,title_text_size=30,title_pos='center',\ subtitle = subtitle,subtitle_text_size = 25,width=800,height= 800) pie.add("", item_name_list, item_num_list,is_label_show=True,center=[50, 45],radius=[0,50],\ legend_pos ='left',legend_orient='vertical',label_text_size=20) out_file_name = './analyse/'+item_name+'.html' #print(out_file_name) pie.render(out_file_name)
def drawPieByTimes(file, length): pr = pd.read_csv(file, nrows=length, encoding='utf-8_sig') labels = [] cnt = [] # 饼状图的标签 for i in pr['单词']: labels.append(i) for i in pr['词频']: cnt.append(int(i)) #print(labels) #print(cnt) pie = Pie('高频词汇一览', '词频最高的单词', title_pos='center') pie.add('词频', labels, cnt, is_legend_show=False) pie.render()
def test_pie_multiple(): import random attr = ['A', 'B', 'C', 'D', 'E', 'F'] pie = Pie("饼图示例", width=1000, height=600) pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[25, 50], is_random=True) pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[25, 50], rosetype='area') pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[65, 50], is_random=True) pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[65, 50], rosetype='radius') pie.render()
def get_charts(x, y, label, type): if type == 1: c = Pie("饼状图") elif type == 2: c = Bar3D("条形图") elif type == 3: c = Line("折线图") print(c) c.add(label, x, y, is_more_utils=True) # 打印输出图表的所有配置项 c.show_config() c.render() os.system(r"render.html")
def showPie(self, title, attr, value): from pyecharts import Pie pie = Pie(title) # pie.add("aa", attr, value, is_label_show=True, title_pos='center') pie.add("", attr, value, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", ) pie.render()
def fromtest(self): from pyecharts import Pie pie = Pie('帖子来源饼形图', self.ftitle, title_pos='center') key, value = pie.cast(self.fromdata) pie.add('帖子数', key, value, is_label_show=True, radius=[35, 65], center=[50, 55], legend_pos='left', legend_orient='vertical') pie.render(r'pic\帖子来源饼形图.html')
def draw_height_pie(data): pie = Pie("妹子身高分布饼图-圆环图", title_pos='center') pie.add("", height_interval, data, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', is_random=True, legend_pos='left') pie.render() return pie
def get_user_dis(): result = userDs.count_user_dis() labels = [] counts = [] for k in result: count = result[k] labels.append(k) counts.append(count) pie = Pie('用户累计跑步距离') pie.add("", labels, counts, is_label_show=True, legend_pos='bottom') fileName = 'user_dis_data.html' pie.render(fileName) return send_file(fileName)
def pie_test5(g5, h5): name = pd.Series(unique(g5)).values g_1 = h5.groupby(g5).sum().round(2).values value = pd.Series(g_1).values pie = Pie("2020年1月到2月各品牌单杯销量在40至60之间饼状分布") pie.add("", name, value, label_text_color=None, is_legend_show=False, is_label_show=True, is_more_utils=True, legend_orient="vertical", legend_pos="left", ) pie.render("F:\\py_data_html\\2020年1月到2月各品牌单杯销量40至60之间饼状分布.html") print("生成完成")
def build_chart_pie(filename,title,datas): axis_x = [str2(key) for key in datas.keys()] axis_y = list(datas.values()) pie = Pie(title,width=400,height=200,title_pos = 'center') pie.add( '',axis_x,axis_y, #'':图例名(不使用图例) radius = [25,55], #环形内外圆的半径 is_label_show = True, #是否显示标签 label_text_color = None, #标签颜色 legend_orient = 'vertical', #图例垂直 legend_pos = 'left', is_more_utils=False ) pie.render(filename)
def drawBarGraph(sizes, labels, title, category, imgName): #饼状图 pie = Pie(title, title_pos='center') # pie.add(category,labels,sizes,is_lable_show=True) pie.add( category, labels, sizes, radius=[40, 75], label_text_color=None, #标签字体的颜色 is_label_show=True, legend_orient='vertical', legend_pos='left') pie.render(path='./%s.png' % imgName)
def draw_gender_Pie(self): data = self.get_single_attribute('gender') attr = list(data.keys()) v1 = list(data.values()) pie = Pie('性别环形图', title_pos='center') pie.add( '', attr, v1, # '':图例名(不使用图例) radius=[40, 75], # 环形内外圆的半径 is_label_show=True, # 是否显示标签 label_text_color=None, # 标签颜色 legend_orient='vertical', # 图例垂直 legend_pos='left' ) pie.render('./gender.html')
def bar_test6(): name = pd.Series(unique(g6)).values g_1 = h6.groupby(g6).sum().round(2).values value = pd.Series(g_1).values pie = Pie("2020年1月到2月香飘飘以及山寨品销量饼状分布") pie.add("", name, value, label_text_color=None, is_legend_show=False, is_label_show=True, is_more_utils=True, legend_orient="vertical", legend_pos="left", ) pie.render("F:\\py_data_html\\2020年1月到2月香飘飘以及山寨品销量饼状分布.html") print("生成完成")
def build_pid(dicall): tings = [] spend = [] for key, value in dicall.items(): tings.append(key) spend.append(value) pie = Pie(" ") pie.add("±ýͼ", tings, spend, legend_orient="vertical", legend_pos="left", center=[75, 50]) pie.render(r'C:\Users\asshole\Desktop\pie.html')
def test_pie_legend(): v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos="center") pie.add( "", CLOTHES, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", ) pie.render()
def drawPie(title, data, savepath='./results'): if not os.path.exists(savepath): os.mkdir(savepath) pie = Pie(title, title_pos='center') #pie.use_theme('westeros') attrs = [i for i, j in data.items()] values = [j for i, j in data.items()] pie.add('', attrs, values, is_label_show=True, legend_orient="vertical", #标签成列 legend_pos="left",# #标签在左 radius=[30, 75], rosetype="area" #宽度属性随值大小变化 ) pie.render(os.path.join(savepath, '%s.html' % title))
def get_country_user_data(): pie = Pie('全国用户分布') map = userDs.get_country_user_data() labels = [] data = [] for k in map: labels.append(k) data.append(map[k]) pie.add("", labels, data, is_label_show=True, legend_pos='bottom') fileName = 'pie.html' pie.render(fileName) return send_file(fileName)
def floor_price(floor, price): attr = ['中', '低', '高'] for i in range(len(floor)): floor[i] = floor[i][0] n1, n2, n3 = [], [], [] for i in range(len(floor)): if floor[i] == attr[0]: # print(size[i]) n1.append(price[i]) # n1.append(size[i]) if floor[i] == attr[1]: n2.append(price[i]) # n2.append(size[i]) if floor[i] == attr[2]: n3.append(price[i]) l = [len(n1), len(n2), len(n3)] ave = [numpy.mean(n1), numpy.mean(n2), numpy.mean(n3)] bar = Bar("楼层_数量价位分布图", "", title_pos="left", width=1200, height=600) bar.add("", attr, ave, is_visualmap=True, visual_text_color='#fff', is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45) overlap.add(bar) line = Line('楼层_数量图', width=1200, height=600) line.add('数量', attr, l, is_stack=True, mark_point=['max', 'min'], line_color='lightblue', is_more_utils=True, visual_range=[0, 50]) overlap.add(line, is_add_yaxis=True, yaxis_index=1) overlap.render('房屋楼层_数量_均价折线图.html') pie = Pie('楼层占比', title_pos='center', width=1200, height=600) pie.add("", attr, l, label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') pie.render('楼层占比Pie.html') print(floor)
def get_province_city_user_data(province): pie = Pie('%s各城市用户分布' % province) listData = userDs.get_province_city_user_data(province) labels = [] data = [] for item in listData: labels.append(item['city']) data.append(item['count']) pie.add("", labels, data, is_label_show=True, legend_pos='bottom') fileName = 'user_city_data.html' pie.render(fileName) return send_file(fileName)
def create_pie(self, attr, value): """生成圆饼图""" pie = Pie("评分-人数占比图") pie.add( "", attr, value, # 图例名(不使用图例) radius=[40, 75], # 环形内外圆的半径 is_label_show=True, # 是否显示标签 label_text_color=None, # 标签颜色 legend_orient='vertical', # 图例垂直 legend_pos='right') pie.render(PIE_PATH) print("圆饼图【成功】")
def get_province_user_age_data(province): pie = Pie('%s用户年龄分布' % province) mapData = userDs.get_province_user_age_data(province) labels = [] data = [] for k in mapData: labels.append(k) data.append(mapData[k]) pie.add("", labels, data, is_label_show=True, legend_pos='bottom') fileName = 'user_age_province.html' pie.render(fileName) return send_file(fileName)
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 get_pie(item_name,item_name_list,item_num_list): totle = item_num_list[0] + item_num_list[1] + item_num_list[2] subtitle = '共有:%d个好友' % totle pie = Pie(item_name,page_title = item_name,title_text_size=30,title_pos='center', subtitle=subtitle,subtitle_text_size = 25,width=800,height=800) pie.add('',item_name_list,item_num_list,is_lable_show=True,center=[50,45],radius=[0,50], legend_pos='left',legend_orient='vertical',lable_text_size=20) analyse_path = './analyse/' if not os.path.exists(analyse_path): os.mkdir(analyse_path) out_file_name = analyse_path + item_name + '.html' pie.render(out_file_name)
def PaintPie(name, school, num): pie = Pie("山东软件大赛一等奖获奖学校统计-饼图", title_pos='center', width=900) pie.add( "山软一等奖获奖学校", school, num, center=[50, 50], is_random=True, radius=[30, 75], rosetype="area", is_legend_show=False, is_label_show=True, ) pie.render(name)
def bingzhuangtu(dict_data, title_info): '''饼状图''' list_key = [] list_values = [] for key, values in dict_data.items(): list_key.append(key) list_values.append(values) # 创建饼图 title_pos:标题位置 pie = Pie(title_info, width=900) # 添加数据 is_random:是否随机排列颜色,默认false pie.add("", list_key, list_values, is_label_show=True) # pie.show_config() pie.render('./img/' + title_info + '.html')
def DrawPie(data, piename=None): from pyecharts import Pie if piename is not None: pie = Pie(piename) else: pie = Pie() try: pie.add('', data[0], data[1], is_label_show=True) except: print( '[Error]: Arguments format error in <utils.py - DrawPie func>...') return None if piename is None: piename = 'results' pie.render('%s.html' % piename)
def drawPie(title, data, savepath='./results'): if not os.path.exists(savepath): os.mkdir(savepath) pie = Pie(title, title_pos='center') attrs = [i for i, j in data.items()] values = [j for i, j in data.items()] pie.add('', attrs, values, is_label_show=True, radius=[30, 50], rosetype="radius", legend_pos="left", legend_orient="vertical") pie.render(os.path.join(savepath, '%s.html' % title))
def analysisSex(self): title = '微信好友性别比' data = {'男': 0, '女': 0, '保密': 0} pie = Pie(title, title_pos='center') for each in self.friends_info.get('sex'): if each == 0: data['保密'] += 1 elif each == 1: data['男'] += 1 elif each == 2: data['女'] += 1 attrs = [i for i, j in data.items()] values = [j for i, j in data.items()] pie.add('', attrs, values, radius=[40, 75], is_label_show=True, label_text_color='#435', legend_orient='vertical', legend_pos='left') pie.render(os.path.join(self.savedir, '%s.html' % title))
def show_male(dict_data): '''饼图展示男女比例''' sex_key_list = [] sex_value_list = [] # 提取数据 for sex_key, sex_value in dict_data.items(): sex_key_list.append(sex_key) sex_value_list.append(sex_value) # 创建饼图 title_pos:标题位置 pie = Pie('男女比例', width=1400) # 添加数据 is_random:是否随机排列颜色,默认false pie.add("", sex_key_list, sex_value_list, is_label_show=True) pie.render('./img/男女比例.html')
def gender_map(): print('gender | 人数') print('------|-----') for bucket in DLDL.gender_aggs( )['aggregations']['terms_gender']['buckets']: print(bucket['key'], '|', bucket['doc_count']) attr = [ "男", "女", ] v1 = [133, 27] pie = Pie("性别分布") pie.add("", attr, v1, is_label_show=True) pie.render()
def test_pie_type_radius(): pie = Pie("饼图示例", title_pos="center", width=1000, height=600) pie.add( "", ["A", "B", "C", "D", "E", "F"], [335, 321, 234, 135, 251, 148], radius=[40, 55], is_label_show=True, ) pie.add( "", ["H", "I", "J"], [335, 679, 204], radius=[0, 30], legend_orient="vertical", legend_pos="left", ) pie.render()
def test_pie_multiple(): import random attr = ["A", "B", "C", "D", "E", "F"] pie = Pie("饼图示例", width=1000, height=600) pie.add( "", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[25, 50], is_random=True, ) pie.add( "", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[25, 50], rosetype="area", ) pie.add( "", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[65, 50], is_random=True, ) pie.add( "", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[65, 50], rosetype="radius", ) pie.render()
def test_pie_default(): v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例") pie.add("", CLOTHES, v1, is_label_show=True) pie.render()
def test_pie(): # pie_0 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例") pie.add("", attr, v1, is_label_show=True) pie.show_config() pie.render() # pie_1 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos='center') pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') pie.show_config() pie.render() # pie_2 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] v2 = [19, 21, 32, 20, 20, 33] pie = Pie("饼图-玫瑰图示例", title_pos='center', width=900) pie.add("商品A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius') pie.add("商品B", attr, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True) pie.show_config() pie.render() # pie_3 pie = Pie("饼图示例", title_pos='center', width=1000, height=600) pie.add("", ['A', 'B', 'C', 'D', 'E', 'F'], [335, 321, 234, 135, 251, 148], radius=[40, 55], is_label_show=True) pie.add("", ['H', 'I', 'J'], [335, 679, 204], radius=[0, 30], legend_orient='vertical', legend_pos='left') pie.show_config() pie.render() # pie_4 import random attr = ['A', 'B', 'C', 'D', 'E', 'F'] pie = Pie("饼图示例", width=1000, height=600) pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[25, 50], is_random=True) pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[25, 50], rosetype='area') pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[65, 50], is_random=True) pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[65, 50], rosetype='radius') pie.show_config() pie.render() # Pie_5 pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center') pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, ) pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left') pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None) pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24], label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center") pie.show_config() pie.render()