Beispiel #1
0
    def pie_count_gender(self):
        """
        用户性别分布
        :return:
        """
        # 分组
        gender_df = self.df.groupby(['gender'])['level'].agg(['count'])
        gender_df.reset_index(inplace=True)

        attr = gender_df['gender']
        v = gender_df['count']

        pie = Pie('用户性别分布')
        pie.add('', attr, v, is_label_show=True, legend_orient="vertical", legend_pos="80%")
        return pie
Beispiel #2
0
def score_rose_render(score):
    from pyecharts import Pie
    attr = list(set(score))
    value = []
    for x in attr:
        value.append(score.count(x))
    Pie("评分玫瑰饼图分布", title_pos='center').add(
        "",
        attr,
        value,
        is_label_show=True,
        is_legend_show=False,
        radius=[40, 75],
        # rosetype="radius",
        rosetype="area").render("score_rose.html")
def drawPie(name, rank, chatroomname):
    outputFile = './result/{}_群性别比例图.html'.format(chatroomname)
    pie = Pie('{} 群性别比例图'.format(chatroomname),
              width=1200,
              height=600,
              title_pos='center')
    pie.add(
        '',
        name,
        rank,
        is_label_show=True,  # 是否显示标签
        label_text_color=None,  # 标签颜色
        legend_orient='vertical',  # 图例是否垂直
        legend_pos='left')
    pie.render(outputFile)
Beispiel #4
0
def nk_to_pie(complaints):
    data = {}
    for i in complaints:
        if i.nk[:4].isdigit():
            nk = i.nk[:4]
            if nk in data.keys():
                data[nk] += 1
            else:
                data[nk] = 1
        else:pass
    attr = list(data.keys())
    value = list(data.values())
    pie = Pie('投诉年款分布图', width=1300)
    pie.add('', attr, value, is_label_show=True)
    return pie
Beispiel #5
0
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')
Beispiel #6
0
 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()
Beispiel #7
0
def bw_to_pie(complaints):
    data = {}
    for i in complaints:
        for i in i.wt.split(','):
            wt = i.split('#')
            if wt[0] in data.keys():
                data[wt[0]] += 1
            else:
                data[wt[0]] = 1
    attr = list(data.keys())
    value = list(data.values())

    pie =  Pie('投诉部位分布图',width=1300)
    pie.add('',attr,value,is_legend_show=False, is_label_show=True)
    return  pie
Beispiel #8
0
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 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)
Beispiel #10
0
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 size_price(size,price):
    #page=Page()
    overlap=Overlap()
    #print(size)
    k=[]
    attr=['0-30','30-60','60-90','90-120','120-150','150及以上']
    for i in range(len(size)):
        size[i]=float(size[i][:-2])
    n1,n2,n3,n4,n5,n6=[],[],[],[],[],[]
    for i in range(len(size)):
        if size[i]<=30:
            #print(size[i])
            n1.append(price[i])
        #n1.append(size[i])
        if 30<size[i]<=60:
            n2.append(price[i])
        #n2.append(size[i])
        if 60< size[i] <= 90:
            n3.append(price[i])
        # n3.append(size[i])
        if 90<size[i]<=120:
            n4.append(price[i])
        #n4.append(size[i])
        if 120<size[i]<=150:
            n5.append(price[i])
        #n5.append(size[i])
        if 150<size[i]:
            n6.append(price[i])
    #n6.append(size[i])
    l=[len(n1),len(n2),len(n3),len(n4),len(n5),len(n6)]
    ave=[numpy.mean(n1),numpy.mean(n2),numpy.mean(n3),numpy.mean(n4),numpy.mean(n5),numpy.mean(n6)]
    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)
    #page.add(bar)
    #bar.render('房屋面积_数量bar.html')
    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])
    #page.add(line)
    overlap.add(line,is_add_yaxis=True,yaxis_index=1)
    #line.render('房屋面积_均价折线图.html')
    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')
Beispiel #12
0
def test_page():
    page = Page()
    line = Line("折线图示例")
    line.chart_id = "id_my_cell_line"
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
    )

    # pie
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center", width="600px")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    page.add([line, pie, create_a_bar(TITLE)])
    # Start render and test
    html = page._repr_html_()
    # Test base html structure
    assert html.count("<script>") == html.count("</script>") == 2
    assert html.count("<div") == html.count("</div>") == 3
    assert html.count("require.config") == html.count("function(echarts)") == 1
    # Test some chart attributes
    json_encoded_title = json.dumps(TITLE)
    assert json_encoded_title in html
    assert "nbextensions/echarts" in html  # default jshost
    assert html.count("height:400px") == 3
    assert html.count("width:600px") == 1
    assert html.count("width:800px") == 2
    assert html.count("id_my_cell_line") == 6
Beispiel #13
0
def pic(data, file):
    all_poet = [i[0] for i in data]
    all_num = [i[1] for i in data]
    pie = Pie(title=file.rstrip('2.txt') + '中的四季', title_pos='center')
    pie.add(
        "",
        all_poet,
        all_num,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    pie.render(path=file.rstrip('2.txt') + '中的四季' + '.html')
Beispiel #14
0
def ePie(myList):
    key = []
    value = []
    for item in myList:
        key.append(item[0])
        value.append(item[1])
    pie = Pie("")
    pie.add("热词",
            key,
            value,
            is_label_show=True,
            is_legend_show=True,
            label_text_color=None,
            legend_orient='vertical',
            legend_pos='left')
    return pie
Beispiel #15
0
    def user_count_pie(self):
        """
        用户地区分布
        :return:
        """
        # 分组
        user_count_df = self.df.groupby(['address'])['level'].agg(['count'])
        overseas = user_count_df['count']['海外']
        nil = user_count_df['count']['无']
        home = user_count_df['count'].sum() - overseas - nil

        attr = ['国内', '海外', '无']
        value = [home, overseas, nil]
        pie = Pie('用户地区分布')
        pie.add("", attr, value, is_label_show=True)
        return pie
Beispiel #16
0
def pie(spi, name):
    """
    :param spi: 接受为元组((),())
    :param name:
    :return:
    """
    attr = []
    v1 = []
    for i in spi:
        attr.append(i[0])
        v1.append(i[1])

    pie_pie = Pie(name, title_pos='center')
    pie_pie.add("", attr, v1, radius=[40, 75], label_text_color=None,
                is_label_show=True, legend_orient='vertical', legend_pos='left')
    return pie_pie.render_embed()
Beispiel #17
0
def mCityAll(dfAll, minit):
    df_ = dfAll.drop('id', axis=1).groupby('city').agg([len])
    attr = list(df_.index)
    value = list(df_['count']['len'])
    pie = Pie("")
    pie.add(
        "各个城市的油站数量",
        attr,
        value,
        is_random=True,
        rosetype="area",
        is_legend_show=False,
        is_label_show=True,
        legend_pos="20%",
    )
    pie.render('img-各个城市的油站数量.html')
def stars_of_bread(data):
    stars = data['Star'].value_counts().sort_index()
    stars_pcc = data.groupby('Star')['Per_Consumption'].mean()
    starts_fig = Pie("Stars of Restaurant", title_pos='center')
    starts_fig.add('', ['0星', '2星', '3星', '3.5星', '4星', '4.5星', '5星'],
                   stars.values,
                   legend_pos='left',
                   legend_orient='vertical',
                   is_label_show=True,
                   rosetype='radius')
    starts_fig.render(os.path.join(data_out, 'stars_of_bread.html'))

    plt.figure()
    # plt.axis(rotation=90)
    stars_pcc.plot(kind='barh')
    plt.show()
Beispiel #19
0
def drawPie(value):
    #画出不同时区的店铺的分布数量饼状图
    dict1 = Counter(value)
    #    print(dict1.keys())
    attr = dict1.keys()
    v = dict1.values()
    pie = Pie("饼图示例", "正代表东,负代表西,数字代表第几个时区,30代表这条记录缺失时区值", title_pos='center')
    pie.add("",
            attr,
            v,
            center=[50, 60],
            is_label_show=True,
            label_text_color=None,
            legend_orient='vertical',
            legend_pos='left')
    pie.render("timezone_pie.html")
Beispiel #20
0
def build_top10_dst_port_diagram(df, logs):
    df_top10_grouped_by_dst_port = None

    if not df.empty:
        df_top10_grouped_by_dst_port = df.groupby('dstport').agg({'msg': 'count'})\
         .sort_values(by='msg').tail(10)

    attr = list(df_top10_grouped_by_dst_port.index
                ) if df_top10_grouped_by_dst_port is not None else {}
    v = list(df_top10_grouped_by_dst_port['msg']
             ) if df_top10_grouped_by_dst_port is not None else {}
    pie = Pie()
    pie.add("DST Port", attr, v)

    logs.update(top10_dst_port_diagram=pie.render_embed())
    logs.update(echart_pie_script_list=pie.get_js_dependencies())
Beispiel #21
0
def create_profession(data, title):
    page = Page()
    style = Style(width=900,
                  height=400,
                  title_pos="center",
                  background_color='#c4ccd3')
    kwargs = dict(radius=(40, 75),
                  label_text_color=None,
                  is_label_show=True,
                  legend_orient='her',
                  legend_pos='left')
    profession_chart = Pie(title, **style.init_style)
    attr, value = profession_chart.cast(data)
    profession_chart.add("", attr, value, **kwargs)
    page.add(profession_chart)
    return page
def ReadOther():
    attr = ["城市社区服务", "环保项目", "帮扶活动", "文体活动", "安全医疗", "法律宣传讲座培训", "其他"]
    value = [373257, 159648, 212721, 246070, 143465, 120205, 93256]
    funnel = Funnel("项目类别统计", width='100%', height='100%', title_pos='center',
                    title_text_size=16, title_color='#3B5077')
    funnel.add("类别统计", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff",
               label_text_size=8, legend_orient="vertical", legend_pos="left", legend_text_size=10)

    name = []
    value = []
    with open('data/全国院校统计前100.csv', 'r', encoding='utf-8') as file:
        reader = csv.reader(file)
        for row in reader:
            name.append(row[2])
            value.append(row[1])
    wordcloud = WordCloud(width='120%', height='100%')
    wordcloud.add("", name, value, word_size_range=[8, 30])

    schema = [
        ("博士研究生", 1000000), ("硕士研究生", 1000000), ("大学本科", 1000000), ("大学专科", 1000000), ("中等专科", 1000000),
        ("技工学校", 1000000), ("高中", 1000000), ("初中", 1000000), ("职业高中", 1000000), ("小学", 1000000),
    ]
    v1 = [[9979, 48300, 716519, 448358, 118656, 36065, 600168, 697599, 54160, 270191]]
    v2 = [[863336, 462984, 953627, 646927, 234893, 170111, 354992, 241914, 158316, 84504]]
    radar = Radar(width='100%', height='110%')
    radar.config(schema)
    radar.add("实际人数分布", v1, is_splitline=True, is_axisline_show=True, label_text_size=8, legend_orient="vertical")
    radar.add("人数比例分布", v2, label_color=["#4e79a7"], is_area_show=False,
              legend_selectedmode='single', legend_pos="right", legend_text_size=10, legend_orient="vertical")

    attr = ["群众", "中国少年先锋队队员", "无党派民主人士", "台湾民主自治同盟盟员", "九三学社社员", "中国致公党党员", "中国农工民主党党员",
            "中国民主促进会会员", "中国民主建国会会员", "中国民主同盟盟员", "中国国民党革命委员会会员", "中国共产主义青年团团员", "中国共产党预备党员", "中国共产党党员"]
    v2 = [34688546, 2725751, 95275, 2180, 713840, 3787, 30049, 7356, 7278, 14952, 21065, 12621879, 294148, 6089445]
    pie = Pie(width='100%', height='90%', title_pos='center', title_text_size=10)
    pie.add("政治面貌统计", attr, v2, center=[50, 50], is_random=True, radius=[10, 80], rosetype="area",
            is_legend_show=True, is_label_show=False, legend_pos="left", legend_text_size=10, legend_orient="vertical")

    attr = ['2005', '2006', '2007', '2008', '2009', '2010', '2011',
            '2012', '2013', '2014', '2015', '2016', '2017', '2018']
    line = Line(width='100%', height='100%')
    line.add("志愿者数增长", attr, [1, 59580, 532707, 258196, 26194, 628465, 311171, 1970707, 1539836,
                              2807952, 6566130, 6775399, 36504414, 7408478], mark_line=["average"])
    line.add("团体增长", attr, [371, 485, 471, 924, 798, 1266, 2887, 4963, 4848, 7781, 24203, 15936, 25280, 5376],
             mark_line=["average"])
    line.add("项目增长", attr, [10, 6, 3, 94, 125, 152, 210, 802, 3209, 10937, 58426, 166609, 341083, 203931],
             mark_line=["average"], legend_text_size=10, yaxis_label_textsize=8, yaxis_margin=2)
    return funnel, wordcloud, radar, pie, line
Beispiel #23
0
    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 make_pie():
    drugs = []
    stocks = []

    res = mysql_conn.exec_readsql("select drug_name,stock from drug_info")

    for i in res:
        drugs.append(i[0])
        stocks.append(i[1])
    print drugs

    #pie = Pie("药品库存显示",title_pos='center',width=900)
    pie = Pie("药品库存显示         药品销量显示", title_pos='center', width=1000)
    pie.add("",
            drugs,
            stocks,
            center=[25, 50],
            is_random=True,
            radius=[30, 75],
            legend_orient="vertical",
            legend_pos="left")
    #pie.add("药品销量情况",drugs,stocks,center=[25,50],is_random=True,radius=[30,75],rosetype='radius')

    drugs = []
    sells = []

    res_2 = mysql_conn.exec_readsql("select drug_name,sum(drug_amount)\
	 	from transaction_list,drug_info where transaction_list.drug_id=drug_info.drug_id\
	 	group by transaction_list.drug_id")

    for i in res_2:
        drugs.append(str(i[0].encode('utf-8')))
        sells.append(str(i[1]))
    for i in drugs:
        print i

    pie.add("药品销量情况",
            drugs,
            sells,
            center=[65, 50],
            is_random=True,
            radius=[30, 75],
            legend_orient="vertical",
            legend_pos="right")

    pie.render('./templates/render_drug.html')
Beispiel #25
0
def PaintRosePie(school, number, name):

    pie = Pie(name, title_pos='center', width=900)
    pie.add(
        "获奖情况",
        school,
        number,
        center=[50, 50],
        is_random=True,
        radius=[30, 75],
        rosetype="area",
        is_legend_show=True,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )
    pie.render(name + '.html')
Beispiel #26
0
    def showPie(self):
        title = '           公司类型'
        attr, value = self.get_company_type()

        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('公司类型.html')
Beispiel #27
0
def test_grid_line_pie():
    line = Line("折线图示例", width=1200)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"], mark_line=["average"])
    line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"],
             mark_line=["average"], legend_pos="20%")
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例", title_pos="55%")
    pie.add("", attr, v1, radius=[45, 65], center=[65, 50], legend_pos="80%",
            legend_orient='vertical')

    grid = Grid()
    grid.add(line, grid_right="55%")
    grid.add(pie, grid_left="60%")
    grid.render()
Beispiel #28
0
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()
Beispiel #29
0
def showHotPie(keys=getHotWords()):
    content = getAllContents()
    labels, values = myCal(content, keys)
    pie = Pie("水利热点比例图", title_pos='center')
    #pie.add("",labels,values,is_label_show=True)
    pie.add(
        "",
        labels,
        values,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )
    # pie.render()
    return pie
Beispiel #30
0
def pie_chart(w=600,
              h=400,
              is_show=True,
              is_toolbox_show=True,
              is_legend_show=True):
    chart = Charts.query.filter_by(name='pie').first()
    current_chart_paras = chart.inf.all()

    pie = Pie(chart.tit,
              "",
              title_pos='center',
              width=w,
              height=h,
              title_color='#fff',
              title_text_size=12)

    attr = []
    v = []

    info = Msg.query.filter()
    for i in current_chart_paras:
        v.append(i.info_value)
        attr.append(i.info_name)

    # 获取JSON数据
    with open('map.json', 'r') as f:
        data = json.load(f)
        num_blue = data["blue"]
        num_red = data["red"]

    label_color = ['#bbd3b1', "#8db978", '#669f40', '#548534']

    # v = [num_red, num_blue]
    pie.add('',
            attr,
            v,
            legend_pos='right',
            legend_orient='vertical',
            rosetype='radius',
            radius=[40, 70],
            legend_text_color='#fff',
            label_color=label_color,
            is_label_show=is_show,
            is_toolbox_show=is_toolbox_show,
            is_legend_show=is_legend_show)
    return pie