Exemple #1
0
def get_friends():
    friends = itchat.get_friends(update=True)[0:]
    male = female = other = 0
    for i in friends[1:]:
        sex = i['Sex']
        if sex == 1:
            male += 1
        elif sex == 2:
            female += 1
        else:
            other += 1
    total = len(friends[1:])

    chart = Echart('friends', 'from WeChat')
    chart.use(
        Pie('WeChat', [{
            'value': male,
            'name': 'male: %.2f%%' % (float(male) / total * 100)
        }, {
            'value': female,
            'name': 'male: %.2f%%' % (float(female) / total * 100)
        }, {
            'value': other,
            'name': 'male: %.2f%%' % (float(other) / total * 100)
        }],
            radius=["%50", "%70"]))
    chart.use(Legend(['male', 'female', 'other']))
    del chart.json['xAxis']
    del chart.json['yAxis']
    chart.plot()
Exemple #2
0
 def yidi_salary_dis(self):
     lst = []
     with codecs.open(r"E:\51job\data\yidi.csv", "r",
                      encoding="utf-8") as f:
         f_csv = csv.reader(f)
         for row in f_csv:
             for i in range(5):
                 lst.append(int(row[i]))
         chart = Echart(u'异地招聘-工资范围分布', '[x,y]包含边界值x和y')
         chart.use(
             Pie('Guangzhou', [{
                 'value': lst[0],
                 'name': '[0,1.0]: %d' % (lst[0])
             }, {
                 'value': lst[1],
                 'name': '[1.1,1.5]: %d' % (lst[1])
             }, {
                 'value': lst[2],
                 'name': '[1.6,2.0]: %d' % (lst[2])
             }, {
                 'value': lst[3],
                 'name': '[2.1,2.5]: %d' % (lst[3])
             }, {
                 'value': lst[4],
                 'name': '>2.5: %d' % (lst[4])
             }],
                 radius=["50%", "70%"]))
         #chart.use(Legend(['Beijing']))
         del chart.json["xAxis"]
         del chart.json["yAxis"]
         chart.plot()
Exemple #3
0
    def city_ratio(self):
        c_list = []
        for i in self.friends:
            city = i['City']
            if city != '':
                c_list.append(city)

        from collections import Counter

        c_dict = dict(Counter(c_list))

        # 使用echarts
        from echarts import Echart, Legend, Pie

        chart = Echart(u'%s的微信各城市好友数量' % (self.friends[0]['NickName']),
                       'from WeChat')
        chart.use(
            Pie('WeChat', [{
                'value': value,
                'name': u'{0}-{1}'.format(name, value)
            } for name, value in c_dict.items()],
                radius=["30%", "70%"]))
        chart.use(Legend(list(name for name, value in c_dict.items())))
        del chart.json['xAxis']
        del chart.json['yAxis']
        chart.plot()

        # 保存图表
        import os
        d = os.path.dirname(__file__)
        chart.save(
            os.path.dirname(__file__) + os.sep,
            '%s的好友城市人数' % (self.friends[0]['NickName']))
Exemple #4
0
def echart_pie(friends):
    total = len(friends) - 1
    male = female = other = 0

    for friend in friends[1:]:
        sex = friend["Sex"]
        if sex == 1:
            male += 1
        elif sex == 2:
            female += 1
        else:
            other += 1
    from echarts import Echart, Legend, Pie
    chart = Echart('%s的微信好友性别比例' % (friends[0]['Name']), 'from WeChat')
    chart.use(
        Pie('WeChat', [{
            'value': male,
            'name': '男性 %.2f%%' % (float(male) / total * 100)
        }, {
            'value': female,
            'name': '女性 %.2f%%' % (float(female) / total * 100)
        }, {
            'value': other,
            'name': '其他 %.2f%%' % (float(other) / total * 100)
        }],
            radius=["50%", "70%"]))
    chart.use(Legend(["male", "female", "other"]))
    del chart.json["xAxis"]
    del chart.json["yAxis"]
    chart.plot()
Exemple #5
0
def totalSex(friends):
    male = female = other = 0
    for i in friends[1:]:
        sex = i["Sex"]
        if sex == 1:
            male += 1
        elif sex == 2:
            female += 1
        else:
            other += 1
    total = len(friends[1:])
    print u"总共好友:%d" % total
    print u"男性好友:%.2f%%" % (float(male) / total * 100)
    print u"女性好友:%.2f%%" % (float(female) / total * 100)
    print u"未知性别:%.2f%%" % (float(other) / total * 100)
    chart = Echart(u'%s的微信好友性别比例' % (friends[0]['NickName']),
                   'from WeChat by xuqidong')
    chart.use(
        Pie('WeChat', [{
            'value': male,
            'name': u'男性 %.2f%%' % (float(male) / total * 100)
        }, {
            'value': female,
            'name': u'女性 %.2f%%' % (float(female) / total * 100)
        }, {
            'value': other,
            'name': u'未知 %.2f%%' % (float(other) / total * 100)
        }],
            radius=["50%", "70%"]))
    chart.use(Legend(["male", "female", "other"]))
    del chart.json["xAxis"]
    del chart.json["yAxis"]
    chart.plot()
Exemple #6
0
Fichier : app.py Projet : bonfy/feb
    def pie():
        lst = [2, 3, 4, 5]
        month = ['Nov', 'Dec', 'Jan', 'Feb']
        data = [dict(value=i, name=j) for i, j in zip(lst, month)]

        chart = Echart('GDP', 'This is a fake chart', axis=False)
        chart.use(Pie('China', data))
        chart.use(Legend(['GDP']))
        return jsonify(chart.json)
Exemple #7
0
    def sexratio(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

        total = len(self.friends[1:])

        male_ratio = float(male) / total * 100
        female_ratio = float(female) / total * 100
        other_ratio = float(other) / total * 100

        print(u"男性好友:%.2f%%" % male_ratio)
        print(u"女性好友:%.2f%%" % female_ratio)
        print(u"其他:%.2f%%" % other_ratio)

        # 使用echarts
        from echarts import Echart, Legend, Pie

        chart = Echart(u'%s的微信好友性别比例' % (self.friends[0]['NickName']),
                       'from WeChat')
        chart.use(
            Pie('WeChat', [{
                'value': male,
                'name': u'男性 %.2f%%' % male_ratio
            }, {
                'value': female,
                'name': u'女性 %.2f%%' % female_ratio
            }, {
                'value': other,
                'name': u'其他 %.2f%%' % other_ratio
            }],
                radius=["50%", "70%"]))
        chart.use(Legend(['male', 'female', 'other']))
        del chart.json['xAxis']
        del chart.json['yAxis']
        chart.plot()

        # 保存图表
        import os
        d = os.path.dirname(__file__)
        chart.save(
            os.path.dirname(__file__) + os.sep,
            '%s的好友性别比例' % (self.friends[0]['NickName']))
    def get_sexInfo(self):
        '''初始化计数器'''
        male = female = other = 0
        '''遍历list,列表里的第一个是自己'''
        for i in self.all_friends:
            sex = i['Sex']
            if sex == 1:
                male += 1
            elif sex == 2:
                female += 1
            else:
                other += 1

        total = len(self.all_friends[1:])

        chart = Echart(u"%s的微信好友性别比例" % (self.all_friends[0]['NickName']),
                       'from Wechat')
        chart.use(
            Pie(
                'Wechat',
                [
                    {
                        'value': male,
                        'name': u"男性 %.2f%%" % (float(male) / total * 100)
                    },
                    {
                        'value': female,
                        'name': u"女性 %.2f%%" % (float(female) / total * 100)
                    },
                    {
                        'value': other,
                        'name': u"其他 %.2f%%" % (float(other) / total * 100)
                    },
                ],
            ))
        chart.use(Legend(["male", "female", "other"]))
        chart.plot()
Exemple #9
0
friends = itchat.get_friends(update=True)[0:]

male = female = other = 0

for i in friends[1:]:
    sex = i["Sex"]
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1
total = len(friends[1:])
chart = Echart('%sfrends' % (friends[0]['NickName']), 'from WeChat')
chart.use(
    Pie('WeChat', [{
        'value': male,
        'name': u'man %.2f%%' % (float(male) / total * 100)
    }, {
        'value': female,
        'name': u'woman %.2f%%' % (float(female) / total * 100)
    }, {
        'value': other,
        'name': u'other %.2f%%' % (float(other) / total * 100)
    }],
        radius=["50%", "70%"]))
chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot(persist=True)
Exemple #10
0
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1

self = friends[0]
total = len(friends) - 1

male_rate = float(male) / total * 100
female_rate = float(female) / total * 100
other_rate = float(other) / total * 100

chart = Echart(u'{}的微信好友的性别比例'.format(self['NickName']), "from WeChat")
chart.use(
    Pie('WeChat', [{
        'value': male,
        'name': u'男性 {:.2f}'.format(male_rate)
    }, {
        'value': female,
        'name': u'女性 {:.2f}'.format(female_rate)
    }, {
        'value': other,
        'name': u'其他 {:.2f}'.format(other_rate)
    }]))
chart.use(Legend(['male', 'female', 'other']))
del chart.json['xAxis']
del chart.json['yAxis']
chart.plot()
for friend in friends[0:]:
    sex = friend["Sex"]
    if sex == 1:
        man += 1
    elif sex == 2:
        women += 1
    else:
        other += 1

print("男性好友:%.2f%%" % (float(man) / total * 100))
print("女性好友:%.2f%%" % (float(women) / total * 100))
print("其他:%.2f%%" % (float(other) / total * 100))
# itchat.send(u'程序消息发送测试','filehelper')

chart = Echart('%s的微信好友性别比例' % (friends[0]['NickName']), 'from Wechat')
chart.use(
    Pie('WeChat', [{
        'value': man,
        'name': '男性 %.2f%%' % (float(man) / total * 100)
    }, {
        'value': women,
        'name': '女性 %.2f%%' % (float(women) / total * 100)
    }, {
        'value': other,
        'name': '其他 %.2f%%' % (float(other) / total * 100)
    }],
        radius=["50%", "70%"]))
chart.use(Legend(['man', 'women', 'other']))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()
Exemple #12
0
import itchat
from echarts import Echart, Legend, Pie
itchat.login()
friends = itchat.get_friends(update=True)
male = female = other = 0
for i in friends[1:]:
    sex = i["Sex"]
    if sex == 1:
        male += 1
    elif sex == 2:
        female + 1
    else:
        other += 1
total = len(friends[1:])
chart = Echart(u'%s的微信好友性别比列' % (friends[0]['NickName']), 'from WeChat')
chart.use(
    Pie('WeChat', [{
        'value': male,
        'name': u'男性 %.2f%%' % (float(male) / total * 100)
    }, {
        'value': female,
        'name': u'女性 %.2f%%' % (float(female) / total * 100)
    }, {
        'value': other,
        'name': u'其他 %.2f%%' % (float(other) / total * 100)
    }]))
chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()
Exemple #13
0
# 展示比例使用百分百圆饼表
from echarts import Echart, Legend, Pie

chart = Echart(u'%s的微信好友性别比例' % friends[0]['NickName'],
               'from Wechat')  # 第一个参数为标题 第二个为解释(签名))
chart.use(
    Pie(
        'WeChat',
        [
            {
                'value': male,
                'name': u'男性%.2f%%' % (float(male) / total * 100)
            },
            {
                'value': female,
                'name': u'女性%.2f%%' % (float(female) / total * 100)
            },
            {
                'value': other,
                'name': u'其他%.2f%%' % (float(other) / total * 100)
            },
        ],
        radius=['50%', '70%']  # 图形的大小
    ))

chart.use(Legend(['male', 'female', 'other']))

del chart.json['xAxis']
del chart.json['yAxis']
chart.plot()  # 执行,生成文件
Exemple #14
0
        return ["chart", {"option": self.setting, "name": self.name}]


class ModelTab(PopUpTab):
    '''
    This class visualize a tab containing a 3D model.
    '''
    def __init__(self, name, model):
        PopUpTab.__init__(self, name, model)
        self.model = model

    @property
    def json(self):
        return ["model", {"model": self.model, "name": self.name}]


if __name__ == '__main__':
    # have a try
    chart = Echart("percentage")
    chart.use(Pie("%", data=[random.randint(10, 30), random.randint(10, 30)]))
    ct = ChartTab("Pie-Chart", chart.json)
    # generate a visualzie option
    vo = Option(default=[Prop(color='red')],
                over=[HyperLink(name="KEGG", url="http://www.kegg.jp")],
                click=[PopUp([ct])],
                right=[CXTMenu({
                    'delete': Delete(True),
                    'expend': Expend(2)
                })])
    print(vo.json)
Exemple #15
0
friends = itchat.get_friends(update=True)[0:]
# 初始化计数器,有男有女,当然,有些人是不填的
male = female = other = 0

# 遍历这个列表,列表里第一位是自己,所以从"自己"之后开始计算
# 1表示男性,2女性
for i in friends[1:]:
    sex = i["Sex"]
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1

# 总数算上,好计算比例啊~
total = len(friends[1:])
print "男性好友:%.2f%%" % (float(male) / total * 100)
print "女性好友:%.2f%%" % (float(female) / total * 100)
print "其他:%.2f%%" % (float(other) / total * 100)
chart = Echart(u'%s的微信好友性别比例' % (friends[0]['NickName']), 'from WeChat')
chart.use(Pie('WeChat',
              [{'value': male, 'name': u'男性 %.2f%%' % (float(male) / total * 100)},
               {'value': female, 'name': u'女性 %.2f%%' % (float(female) / total * 100)},
               {'value': other, 'name': u'其他 %.2f%%' % (float(other) / total * 100)}],
              radius=["50%", "70%"]))
chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()
Exemple #16
0
from echarts import Echart, Legend, Pie, Axis

chart = Echart('Map Picks in MLG', 'In group A')
chart.use(
    Pie('Map Picks in MLG', [{
        'value': 2,
        'name': 'de_dust2'
    }, {
        'value': 3,
        'name': 'de_cache'
    }, {
        'value': 12,
        'name': 'de_mirage'
    }, {
        'value': 9,
        'name': 'de_inferno'
    }],
        radius=["50%", "70%"]))
chart.use(Legend(["de_dust2", "de_cache", "de_mirage", "de_inferno"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.save(path='./out/', name='sample')
Exemple #17
0
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1
total = len(friends[1:])

print total

print "男性好友:%.2f%%" % (float(male) / total * 100)
print "女性好友:%.2f%%" % (float(female) / total * 100)
print "未备注好友:%.2f%%" % (float(other) / total * 100)

chart = Echart('%s的微信好友性别比例' % (friends[0]), 'from WeChat')
chart.use(
    Pie('WeChat', [{
        'value': male,
        'name': "男性好友:%.2f%%" % (float(male) / total * 100)
    }, {
        'value': male,
        'name': "女性好友:%.2f%%" % (float(female) / total * 100)
    }, {
        'value': male,
        'name': "未备注好友:%.2f%%" % (float(other) / total * 100)
    }],
        radius=["20%", "40%"]))

chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()
Exemple #18
0
        female += 1
    else:
        other += 1

#计算朋友总数
total = len(friends[1:])
print("好友总数是:", total)

#打印出自己好友的性别比例
print("男性好友: %.2f%%" % (float(male) / total * 100) + "\n" + "女性好友: %.2f%%" %
      (float(female) / total * 100) + "\n" + "不明性别好友: %.2f%%" %
      (float(other) / total * 100))

#使用饼图打印出自己好友的性别比例
chart = Echart('%s的微信好友性别比例' % (friends[0]['NickName']), 'from Wechat')
chart.use(
    Pie('Wechat', [{
        'Value': male,
        "name": '男性好友: %.2f%%' % (float(male) / total * 100)
    }, {
        'Value': female,
        "name": '女性好友: %.2f%%' % (float(female) / total * 100)
    }, {
        'Value': other,
        "name": '不明性别好友: %.2f%%' % (float(other) / total * 100)
    }],
        radius=["50%", "70%"]))
chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()