pyecharts.Pie

Here are the examples of the python api pyecharts.Pie taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

3 Source : views.py
with GNU General Public License v3.0
from 41xu

def calage(appid):
    app=appInfo.objects.get(appid=appid)
    attr=['24岁以下','25-30岁','31-35岁','36-40岁','40岁以上']
    pie=Pie(app.name+"年龄分布")
    pie.add("",attr,[app.age_24,app.age_25_30,app.age_31_35,app.age_36_40,app.age_40],is_label_show=True)
    return pie

def calgender(appid):

3 Source : views.py
with GNU General Public License v3.0
from 41xu

def calgender(appid):
    app=appInfo.objects.get(appid=appid)
    attr=['male','female']
    pie=Pie(app.name+"性别比例")
    pie.add("",attr,[app.male,app.female],is_label_show=True)
    return pie

if __name__=='__main__':

3 Source : uilt.py
with MIT License
from agamgn

def pie_chart():
    warehouses = db.session.query(func.count(warehouse.warehouse_goods_num),
                                  goods.goods_name).filter(warehouse.warehouse_goods_name == goods.goods_name).group_by(
        warehouse.warehouse_supplier_name
    ).all()
    print(warehouses)
    attr = [i for _, i in warehouses]
    v1 = [j for j, _ in warehouses]
    print(attr)
    print(v1)
    pie = Pie("")

    pie.add("", attr, v1, is_stack=True, is_smooth=True, is_fill=True, rosetype="area", is_label_show=True)
    return pie



# 生成编号
def on_created():

3 Source : 诗中的春夏秋冬.py
with MIT License
from ZubinGou

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')


def analye(file):

0 Source : baseAnalyse.py
with GNU General Public License v3.0
from ContrapunctusXIV

def TypeAnalyse():
    chatrooms_single = getChat.GetChatrooms(typename=2)
    single_type_counter_to = {}
    single_type_counter_from = {}
    for i in chatrooms_single:
        sql1 = "SELECT Type,count(*) as num FROM "+i+" WHERE Des=0 GROUP BY Type"
        sql2 = "SELECT Type,count(*) as num FROM "+i+" WHERE Des=1 GROUP BY Type"
        with sqlInit.MysqlInit() as mysql_cur:
            mysql_cur.execute(sql1)
            result = mysql_cur.fetchall()
            for j in result:
                if j[0] in single_type_counter_to.keys():
                    single_type_counter_to[j[0]] += j[1]
                else:
                    single_type_counter_to[j[0]] = j[1]
        with sqlInit.MysqlInit() as mysql_cur:
            mysql_cur.execute(sql2)
            result = mysql_cur.fetchall()
            for j in result:
                if j[0] in single_type_counter_from.keys():
                    single_type_counter_from[j[0]] += j[1]
                else:
                    single_type_counter_from[j[0]] = j[1]

    if 10002 in single_type_counter_to.keys():
        if not 10000 in single_type_counter_to.keys():
            single_type_counter_to[10000] = single_type_counter_to[10002]
        else:
            single_type_counter_to[10000] += single_type_counter_to[10002]
            del single_type_counter_to[10002]
    if 10002 in single_type_counter_from.keys():
        if not 10000 in single_type_counter_from.keys():
            single_type_counter_from[10000] = single_type_counter_from[10002]
        else:
            single_type_counter_from[10000] += single_type_counter_from[10002]
            del single_type_counter_from[10002]

    if 62 in single_type_counter_to.keys():
        if not 43 in single_type_counter_to.keys():
            single_type_counter_to[43] = single_type_counter_to[62]
        else:
            single_type_counter_to[43] += single_type_counter_to[62]
            del single_type_counter_to[62]
    if 62 in single_type_counter_from.keys():
        if not 43 in single_type_counter_from.keys():
            single_type_counter_from[43] = single_type_counter_from[62]
        else:
            single_type_counter_from[43] += single_type_counter_from[62]
            del single_type_counter_from[62]
    define_dict = {"文字":1,"图片":3,"语音":34,"名片":42,"视频":43,"表情":47,"定位":48,"链接":49,"微信电话":50,"系统消息":10000}
    attr = ["文字", "表情", "图片", "视频", "语音", "名片", "定位", "链接", "微信电话", "系统消息"]
    v1 = [single_type_counter_to[define_dict[i]] for i in attr]
    v2 = [single_type_counter_from[define_dict[i]] for i in attr]
    pie = Pie("", width=1000,height=400)
    pie.add(
        "发出",
        attr,
        v1,
        center=[25, 50],
        is_random=True,
        radius=[30, 75],
        is_legend_show=True,
        is_label_show=True,
        legend_top="bottom"
    )
    pie.add(
        "接收",
        attr,
        v2,
        center=[75, 50],
        is_random=True,
        radius=[30, 75],
        is_legend_show=True,
        is_label_show=True,
        legend_top="bottom"
    )
    pie.render(path="../../output/type_ana.html")
    pie.render(path="../../output/type_ana.pdf")

def RowAnalyse():

0 Source : basicData.py
with GNU General Public License v3.0
from ContrapunctusXIV

def TypeAnalyse(chatrooms_single, filename="Type_ana", start_time="1970-01-02", end_time=""):
    single_type_counter_to = {1:0, 3:0, 34:0, 42:0, 43:0, 47:0, 48:0, 49:0, 50:0, 10000:0}
    single_type_counter_from = {1:0, 3:0, 34:0, 42:0, 43:0, 47:0, 48:0, 49:0, 50:0, 10000:0}
    for i in chatrooms_single:
        for j in basicTool.GetData(i,["Type","Des"],start_time=start_time,end_time=end_time,Type=2):
            if j[1] == 0:
                if j[0] in single_type_counter_to.keys():
                    single_type_counter_to[j[0]] += 1
                else:
                    single_type_counter_to[j[0]] = 1
            else:
                if j[0] in single_type_counter_from.keys():
                    single_type_counter_from[j[0]] += j[1]
                else:
                    single_type_counter_from[j[0]] = j[1]

    if 10002 in single_type_counter_to.keys():
        if not 10000 in single_type_counter_to.keys():
            single_type_counter_to[10000] = single_type_counter_to[10002]
        else:
            single_type_counter_to[10000] += single_type_counter_to[10002]
            del single_type_counter_to[10002]
    if 10002 in single_type_counter_from.keys():
        if not 10000 in single_type_counter_from.keys():
            single_type_counter_from[10000] = single_type_counter_from[10002]
        else:
            single_type_counter_from[10000] += single_type_counter_from[10002]
            del single_type_counter_from[10002]

    if 62 in single_type_counter_to.keys():
        if not 43 in single_type_counter_to.keys():
            single_type_counter_to[43] = single_type_counter_to[62]
        else:
            single_type_counter_to[43] += single_type_counter_to[62]
            del single_type_counter_to[62]
    if 62 in single_type_counter_from.keys():
        if not 43 in single_type_counter_from.keys():
            single_type_counter_from[43] = single_type_counter_from[62]
        else:
            single_type_counter_from[43] += single_type_counter_from[62]
            del single_type_counter_from[62]

    define_dict = {"文字":1,"图片":3,"语音":34,"名片":42,"视频":43,"表情":47,"定位":48,"链接":49,"微信电话":50,"系统消息":10000}
    attr = ["文字", "表情", "图片", "视频", "语音", "名片", "定位", "链接", "微信电话", "系统消息"]
    v1 = [single_type_counter_to[define_dict[i]] for i in attr]
    v2 = [single_type_counter_from[define_dict[i]] for i in attr]
    pie = Pie("", width=1000,height=400)
    pie.add(
        "发出",
        attr,
        v1,
        center=[25, 50],
        is_random=True,
        radius=[30, 75],
        is_legend_show=True,
        is_label_show=True,
        legend_top="bottom"
    )
    pie.add(
        "接收",
        attr,
        v2,
        center=[75, 50],
        is_random=True,
        radius=[30, 75],
        is_legend_show=True,
        is_label_show=True,
        legend_top="bottom"
    )
    pie.render(path=filename+".html")
    # pie.render(path=filename+".pdf")

def RowAnalyse(chatrooms_single,filename="Row_ana", start_time="1970-01-02", end_time=""):

0 Source : openadoor.py
with Apache License 2.0
from PKUJohnson

def zdf_distribution(date_zdffb, save_path_zdffb):
    # tushare
    stockbasicinfo = ts.get_stock_basics()

    '''代码排序'''
    stockbasicinfo = stockbasicinfo.sort_index()

    '''股票总数'''
    stocknum = len(stockbasicinfo)
    # stockcode = stockbasicinfo.index[0]

    # 所有票的url拼接地址,用sina api去获取数据,因为tushare获取实时数据不稳定
    urllist = []
    for i in range(0, stocknum):
        stockcode = stockbasicinfo.index[i]
        stockcodeint = int(stockbasicinfo.index[i])
        if stockcodeint >= 600000:
            urllist.append('sh' + str(stockcode))
        else:
            urllist.append('sz' + str(stockcode))
    urllen = len(urllist)
    # print(urllen, urllist)
    (x, y) = divmod(urllen, 9)
    urlchar = ','.join(urllist)
    # print(urlchar)
    # 总共分成9份,因为sina每次请求不超过800
    urlbase = 'http://hq.sinajs.cn/list='
    url1 = urlbase + urlchar[0:9*x-1]
    url2 = urlbase + urlchar[9*x*1:9*x*2-1]
    url3 = urlbase + urlchar[9*x*2:9*x*3-1]
    url4 = urlbase + urlchar[9*x*3:9*x*4-1]
    url5 = urlbase + urlchar[9*x*4:9*x*5-1]
    url6 = urlbase + urlchar[9*x*5:9*x*6-1]
    url7 = urlbase + urlchar[9*x*6:9*x*7-1]
    url8 = urlbase + urlchar[9*x*7:9*x*8-1]
    url9 = urlbase + urlchar[9*x*8:]
    datatemp1 = requests.get(url1)
    datatemp2 = requests.get(url2)
    datatemp3 = requests.get(url3)
    datatemp4 = requests.get(url4)
    datatemp5 = requests.get(url5)
    datatemp6 = requests.get(url6)
    datatemp7 = requests.get(url7)
    datatemp8 = requests.get(url8)
    datatemp9 = requests.get(url9)
    # 获取的数据进行合并
    urldata = datatemp1.text + datatemp2.text + datatemp3.text + datatemp4.text + datatemp5.text + datatemp6.text + datatemp7.text + datatemp8.text + datatemp9.text
    urlsplit = re.split(r'=', urldata)
    # print(len(urlsplit))
    validnum = 0
    validzflist = []
    validyes10 = 0
    validyes7 = 0
    validyes5 = 0
    validyes3 = 0
    validyes1 = 0
    validyes0 = 0
    valid0 = 0
    validno0 = 0
    validno1 = 0
    validno3 = 0
    validno5 = 0
    validno7 = 0
    validno10 = 0
    # 数据分割,提取,整理
    for i in range(1, len(urlsplit)):
        if len(urlsplit[i]) > 100:
            urldataone = re.split(r',', urlsplit[i])
            yesprice = float(urldataone[2])
            nowprice = float(urldataone[3])
            amount = float(urldataone[9])
            buyonevol = float(urldataone[10])
            sellonevol = float(urldataone[20])
            if amount   <   0.1:
                pass
            else:
                if nowprice  <  0.1:
                    pass
                else:
                    if yesprice  <  0.1:
                        pass
                    else:
                        zdf = int(10000*(nowprice/yesprice - 1) + 0.5)/100
                        if abs(zdf)  <  11:
                            validnum += 1
                            validzflist.append(zdf)
                            if zdf >= 9.8 and sellonevol  <  0.1:
                                validyes10 += 1
                            if zdf >= 7 and sellonevol > 0.1:
                                validyes7 += 1
                            if 5  < = zdf  <  7:
                                validyes5 += 1
                            if 3  < = zdf  <  5:
                                validyes3 += 1
                            if 1  < = zdf  <  3:
                                validyes1 += 1
                            if 0.0001  < = zdf  <  1:
                                validyes0 += 1
                            if abs(zdf)  < = 0.0001:
                                valid0 += 1
                            if -1  <  zdf  <  -0.0001:
                                validno0 += 1
                            if -3  <  zdf  < = -1:
                                validno1 += 1
                            if -5  <  zdf  < = -3:
                                validno3 += 1
                            if -7  <  zdf  < = -5:
                                validno5 += 1
                            if zdf  < = -7 and buyonevol > 0.1:
                                validno7 += 1
                            if zdf  < = -9.8 and buyonevol  <  0.1:
                                validno10 += 1
    # 数据整理
    v11 = [0, 0, 0, 0, 0, 0, 0, validyes0, validyes1, validyes3, validyes5, validyes7, 0]
    v22 = [0, validno7, validno5, validno3, validno1, validno0, 0, 0, 0, 0, 0, 0, 0]
    v00 = [0, 0, 0, 0, 0, 0, valid0, 0, 0, 0, 0, 0, 0]
    vzt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, validyes10]
    vdt = [validno10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    attr = ['-10%', '>-7%', '-7~5%', '-5~3%', '-3~1%', '-1~0%', '0', '0~1%', '1~3%', '3~5%', '5~7%', '>7%', '10%']

    # 调用pyecharts
    title = ' 涨跌分布:↑' + str(validyes0+validyes1+validyes3+validyes5+validyes7+validyes10) +  \
            ' ↓' + str(validno0+validno1+validno3+validno5+validno7+validno10) + '  →' + str(valid0)
    subtitle = ' Add_wx_friends: sleepingmoney'
    # bar
    bar = Bar(title, subtitle, title_pos=0.1, subtitle_text_size=15, subtitle_color='#aa8')
    bar.use_theme("shine")
    bar.add("涨", attr, v11, bar_category_gap=0, mark_point=['max', 'average'])
    bar.add("", attr, vzt, bar_category_gap=0, mark_point=['max'])
    bar.add("平", attr, v00, bar_category_gap=0, mark_point=['max'])
    bar.add("跌", attr, v22, bar_category_gap=0, mark_point=['max', 'average'])
    bar.add("", attr, vdt,  bar_category_gap=0, mark_point=['max'])
    # pie
    attrpie = ['涨', '平', '跌']
    vpie = [validyes0+validyes1+validyes3+validyes5+validyes7+validyes10,valid0, validno0+validno1+validno3+validno5+validno7+validno10]
    pie = Pie("涨跌饼图", title_pos='center', width=400, height=400)
    pie.add("", attrpie, vpie, radius=[6, 15], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left')
    bar_render_path = save_path_zdffb[:-12] + 'bar_tozoom_' + date_zdffb + '.png'
    pie_render_path = save_path_zdffb[:-12] + 'pie_tozoom_' + date_zdffb + '.png'
    pie.render(path=pie_render_path)
    bar.render(path=bar_render_path)
    pic_zoom(bar_render_path, save_path_zdffb, 830)
    print('zdf_distribution done: ' + save_path_zdffb)
    return save_path_zdffb


# 163大盘分时
# http://img1.money.126.net/chart/hs/time/540x360/0000001.png

# tgbhotstock
def hot_tgb(date_tgbhotstock, save_path_tgbhotstock):

0 Source : analyze_wechat.py
with MIT License
from vwin

def getSexCount(sexs, countName):
    labels = [u"男", u"女", u"未知"]
    sizes = [sexs["男"], sexs["女"], sexs["未知"]]
    print(sizes)
    pie = Pie("群性别分布")
    pie.add("", labels, sizes, radius=[40, 75], is_label_show=True)
    pie.render(path="./性别分布.html")

    # colors = ["red", "yellow", "blue", "green"]
    # explode = (0, 0, 0)
    # patches, l_text, p_text = plot.pie(
    #     sizes,
    #     explode=explode,
    #     labels=labels,
    #     colors=colors,
    #     labeldistance=1.1,
    #     autopct="%2.0f%%",
    #     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
    # plot.axis("equal")
    # plot.legend(loc="upper left", bbox_to_anchor=(-0.1, 1))
    # # plot.rcParams["font.sans-serif"] = ["./SimHei.ttf"]
    # plot.rcParams["axes.unicode_minus"] = False
    # plot.title(countName)
    # plot.grid()
    # plot.show()


# 制作词云
def makeWorldCount(userName):