class SexPercentPie(object): def __init__(self, friends, theme="red"): self.friends = friends self.pie = Pie("{}的微信好友性别占比".format(friends[0]["NickName"])) self.attr = ["男性好友", "女性好友", "其他"] def render(self): male = female = other = 0 for i in self.friends[1:]: sex = i['Sex'] if sex == 1: male += 1 elif sex == 2: female += 1 else: other += 1 v1 = [male, female, other] self.pie.add("", self.attr, v1, is_label_show=True) self.pie.show_config() total = len(self.friends[1:]) male_friend_percent = float(male) / total * 100 female_friend_percent = float(female) / total * 100 other_friend_percent = float(other) / total * 100 print("好友总数:{}".format(total)) print("男性好友:{:.2f},个数:{}".format(male_friend_percent, male)) print("女性好友:{:.2f},个数:{}".format(female_friend_percent, female)) print("其他:{:.2f},个数{}".format(other_friend_percent, other)) image_path = "images/sexPercentPie.png" self.pie.render(image_path) return image_path
def lookpie(self): # 获取表数据 # 读取文件内容 pi_table = pd.read_excel(path + '名片信息表.xlsx', sheet_name='data') # 获取城市信息 citattr = pi_table['city'].values # 判断是否有城市信息 if len(citattr) == 0: # 没有信息提示 QMessageBox.information(self, '提示信息', '没有联系人') return attr = [] v1 = [] # 循环表里city项 for i in citattr: # 判断city项是否包含在attr里 if not i in attr: # 不包含在attr表里时候添加到attr里 attr.append(i) # Counter(计数器)是对字典的补充,用于追踪值的出现次数。 d = collections.Counter(citattr) # 循环城市列表 for k in attr: # d[k] 是k在列表d中出现的次数 v1.append(d[k]) # 生成饼图 pie = Pie("联系人分布") pie.add("", attr, v1, is_label_show=True) pie.show_config() pie.render(path + '联系人分布饼图.html') # 显示饼图 htmlwidows.set('联系人分布', '联系人分布饼图.html') htmlwidows.show() pass
def pie_test(d, b): name = pd.Series(unique(d)).values g1 = b.groupby(d).sum().round(2).values value = pd.Series(g1).values pie = Pie("各品牌出库数据") pie.add("", name, value, is_label_show=True) pie.show_config() pie.render("E:\\py_data_html\\bar_test015_5.html") print("生成完成")
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 get_charts(x, y, label, type1): if type1 == 1: c = Pie("Pie") elif type1 == 2: c = Bar("Bar") elif type1 == 3: c = Line("各个法院的诉讼结果文档数目分析") c.add(label, x, y, is_more_utils=True) c.show_config() c.render("court_analysis_line.html") os.system("start firefox court_analysis_line.html")
def pie_render(self, render_name, mothed_name, name, productid, projectid, t_time): pie = Pie(render_name, is_animation=False) pie.add("", list(mothed_name(productid, projectid).keys()), list(mothed_name(productid, projectid).values()), is_label_show=True, is_toolbox_show=False) pie.show_config() pie.render(path=os.path.join(html_path, "%s_%s.html" % (name, t_time)))
def make_pie(): from pyecharts import Pie attr = ['OPPO', '小米', '苹果', '华为', '中兴', '其他'] iphone = [ name['OPPO'], name['苹果'], name['小米'], name['华为'], name['其他'], name['中兴'] ] pie = Pie('苏宁——智能手机') pie.add('手机品牌', attr, iphone, is_label_show=True) pie.show_config() pie.render(path='./suNing.html')
def get_charts(x,y,label,type1): if type1 == 1: c = Pie("Pie") elif type1 == 2: c = Bar("Bar") elif type1 == 3: c = Line("诉讼结果文档1945-2018趋势图") c.add(label,x,y,is_more_utils=True) c.show_config() c.render("year_analysis_line.html") os.system("start year_analysis_line.html")
def get_charts(x, y, label, type1): if type1 == 1: c = Pie("Pie") elif type1 == 2: c = Bar("Bar") elif type1 == 3: c = Line("Line") c.add(label, x, y, is_more_utils=True) c.show_config() c.render("name_analysis_line.html") os.system("start name_analysis_line.html")
def get_charts(x, y, label, type): if type == 1: c = Pie("饼状图") elif type == 2: c = Bar("条形图") elif type == 3: c = Line("折线图") c.add(label, x, y, is_more_utils=True) c.show_config() c.render() os.system(r"render.html")
def draw_pie_mulit(): 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()
def get_html(): # encoding:utf-8 ''' add(name,attr,value,radius = None,center = None,rosetype = None,**kwargs) attr:属性名称 radius:饼图半径,数组第一项是内径,第二项是外径,默认[0,75,],设置成百分比 center:圆心,数组第一项是X轴,第二项是Y轴,默认[50,50] rosetype: 是否展示成南丁格尔图,用过半径区分数据大小,radius和area两种模式,默认radius''' pie1 = Pie('') # 创建实例 attr = [] #餐厅 value1 = [] #次数 pie1.add('', attr, value1, is_label_show=True) ''' 如果需要横向并列图 可在最后的add括号中添加 (---snip---,is_convert = True) 表示X 轴与 Y 轴交换 ''' pie1.show_config() # 调试输出pyecharts的js配置信息 pie1.render('饼图.html')
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()
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(path='./data/01-多个饼图.html')
# bar.use_theme('dark') X_AXIS = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] bar.add("商家A", X_AXIS, [random.randint(10, 100) for _ in range(6)]) bar.add("商家B", X_AXIS, [random.randint(10, 100) for _ in range(6)]) bar.add("商家C", X_AXIS, [random.randint(10, 100) for _ in range(6)]) bar.add("商家D", X_AXIS, [random.randint(10, 100) for _ in range(6)]) bar.render('./文件/案例2_柱形图dark.html') # 饼图Pie from pyecharts import Pie attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例") #新建饼图示例pie pie.add("", attr, v1, is_label_show=True) pie.show_config() #是否在命令行中显示config,此行可省略 pie.render("./文件/案例2_普通饼图示例.html") # 玫瑰饼图 from pyecharts import Pie attr = ['衬衣', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] v1 = [5, 9, 22, 6, 9, 30] v2 = [5, 9, 22, 6, 9, 30] pie = Pie('饼图-玫瑰图示例', title_pos='right', width=1200, height=700) #pie.use_theme('vintage') # add() # center为调整饼图圆心坐标 # is_random为是否随即排列颜色列表(bool) # radius为半径,第一个为内半径,第二个是外半径 # rosetype为是否展示成南丁格尔图:'radius' 圆心角展现数据半分比,半径展现数据大小;'area'圆心角相同,为通过半径展现数据大小(默认) # label_text_size为调整标签字体大小
def create_sex(FSex): sex = dict() # 4.1提取好友性别信息,从1开始,因为第0个是自己 for f in FSex[1:]: if f == 1: # 男 sex["man"] = sex.get("man", 0) + 1 elif f == 2: # 女 sex["women"] = sex.get("women", 0) + 1 else: # 未知 sex["unknown"] = sex.get("unknown", 0) + 1 # 在屏幕上打印出来 total = len(friends[1:]) # 4.2打印出自己的好友性别比例 print("男性好友: %.2f%%" % (float(sex["man"]) / total * 100) + "n" + "女性好友: %.2f%%" % (float(sex["women"]) / total * 100) + "n" + " 不明性别好友: %.2f%%" % (float(sex["unknown"]) / total * 100)) # 4.3柱状图展示好友比例 for i, key in enumerate(sex): plt.bar(key, sex[key]) plt.savefig("getsex.png") # 保存图片 plt.ion() plt.pause(5) plt.close() # 图片显示5s,之后关闭 # 4.4用饼装图显示好友比例 # ----------设置中文显示----------------- mpl.rcParams['font.sans-serif'] = ['SimHei'] font_size = 11 # 字体大小 # 更新字体大小 mpl.rcParams['font.size'] = font_size # 调节图形大小,宽,高 plt.figure(figsize=(6, 9)) # 定义饼状图的标签,标签是列表 labels = [u'男性好友', u'女性好友', u'性别不明'] # 每个标签占多大,会自动去算百分比 sizes = [sex["man"], sex["women"], sex["unknown"]] colors = ['red', 'yellowgreen', 'lightskyblue'] # 将某部分爆炸出来, 使用括号,将第一块分割出来,数值的大小是分割出来的与其他两块的间隙 explode = (0.05, 0, 0) patches, l_text, p_text = plt.pie(sizes, explode=explode, labels=labels, colors=colors, labeldistance=1.1, autopct='%3.1f%%', shadow=False, startangle=90, pctdistance=0.6) for t in l_text: t.set_size(30) for t in p_text: t.set_size(20) # 设置x,y轴刻度一致,这样饼图才能是圆的 plt.axis('equal') plt.legend() plt.show() # 4.5使用echarts饼状图 attr = ['帅哥', '美女', '未知'] value = [sex["man"], sex["women"], sex["unknown"]] pie = Pie('好友性别比例', '好友总人数:%d' % len(friends), title_pos='center') pie.add('', attr, value, radius=[30, 75], rosetype='area', is_label_show=True, is_legend_show=True, legend_top='bottom') pie.show_config() pie.render('好友性别比例.html')
from pyecharts import Pie bar = Pie("我的第一个图表", "这里是副标题") bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90]) bar.show_config() bar.render("pie.html")
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()