Пример #1
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']))
Пример #2
0
def test_axis():
    chart = Echart('Axis', 'Proportion of Browser')
    assert len(chart.json['xAxis'][0]) == 0
    assert len(chart.json['yAxis'][0]) == 0
    chart.use(Axis('category', 'bottom', 'proportion', inverse=True))
    assert chart.json['xAxis']
    chart.use(Axis('category', 'left', 'proportion', inverse=True))
    assert chart.json['yAxis']
    map(repr, chart.x_axis)
Пример #3
0
 def bar():
     chart = Echart('GDP', 'This is a fake chart')
     chart.use(Bar('China', [2, 3, 4, 5]))
     chart.use(Legend(['GDP']))
     chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan',
                                                'Feb']))
     return jsonify(chart.json)
Пример #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()
Пример #5
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()
Пример #6
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()
def display_temperature():
    #url各区为华北,东北,华东,华中,华南,西北,西南
    urls = [
        'http://www.weather.com.cn/textFC/hb.shtml',
        'http://www.weather.com.cn/textFC/db.shtml',
        'http://www.weather.com.cn/textFC/hd.shtml',
        'http://www.weather.com.cn/textFC/hz.shtml',
        'http://www.weather.com.cn/textFC/hn.shtml',
        'http://www.weather.com.cn/textFC/xb.shtml',
        'http://www.weather.com.cn/textFC/xn.shtml'
    ]
    #循环传各区url参数并执行get气温函数
    for url in urls:
        get_temperature(url)
        time.sleep(2)  #每爬一个页面停顿防止过度干扰服务器不友好
    #对执行完获得全国最高温进行排序
    SORTED_TEMPERATURE_LIST = sorted(TEMPERATURE_LIST,
                                     key=(lambda x: (int(x['max']))),
                                     reverse=True)
    #,页面显示不了这么多,故筛选排前20的并定义新变量赋值
    TOP20_TEMPERATURE_LIST = SORTED_TEMPERATURE_LIST[0:20]
    TOP20_CITY_LIST = []
    OP20_MAX_LIST = []
    for city_max in TOP20_TEMPERATURE_LIST:
        TOP20_CITY_LIST.append(city_max['city'])
        TOP20_MAX_LIST.append(city_max['max'])
    #用echarts库进行可视化制图
    echart = Echart(u'全国最高气温排名TOP1~20')
    bar = Bar(u'最高温度', TOP20_MAX_LIST)
    axis = Axis('category', 'left', data=TOP20_CITY_LIST)
    echart.use(bar)
    echart.use(axis)
    echart.plot()
Пример #8
0
def main():
    # urls=['http://www.weather.com.cn/textFC/hb.shtml',
    #       'http://www.weather.com.cn/textFC/db.shtml',
    #       'http://www.weather.com.cn/textFC/hd.shtml',
    #       'http://www.weather.com.cn/textFC/hz.shtml',
    #       'http://www.weather.com.cn/textFC/hn.shtml',
    #       'http://www.weather.com.cn/textFC/xb.shtml',
    #       'http://www.weather.com.cn/textFC/xn.shtml',
    #       ]
    # for url in urls:
    #     get_temperature(url)
    #     time.sleep(2)
    #
    # line =  json.dumps(TEMPERATUR_LIST, ensure_ascii=False)
    # with open('temperature.json','w') as fp:
    #     fp.write(line.encode('utf-8'))

    with open('temperature.json', 'r') as fp:
        TEMPERATUR_LIST = json.load(fp, encoding='utf-8')

    SORTED_TEMPERATURE_LIST = sorted(
        TEMPERATUR_LIST, lambda x, y: cmp(int(y['max']), int(x['max'])))
    TOP20_TEMPERATURE_LIST = SORTED_TEMPERATURE_LIST[0:20]
    TOP20_CITY_LIST = []
    TOP20_MAX_LIST = []
    for city_max in TOP20_TEMPERATURE_LIST:
        TOP20_CITY_LIST.append(city_max['city'])
        TOP20_MAX_LIST.append(city_max['max'])

    echart = Echart(u'全国最高温度排名', u'ZG爬虫')
    bar = Bar(u'最高温度', TOP20_MAX_LIST)
    axis = Axis('category', 'bottom', data=TOP20_CITY_LIST)
    echart.use(bar)
    echart.use(axis)
    echart.plot()
Пример #9
0
def main():
    urls = [
        'http://www.weather.com.cn/textFC/hz.shtml']
    # 'http://www.weather.com.cn/textFC/hb.shtml',
    # 'http://www.weather.com.cn/textFC/db.shtml',
    # 'http://www.weather.com.cn/textFC/hd.shtml',
    # 'http://www.weather.com.cn/textFC/hn.shtml',
    # 'http://www.weather.com.cn/textFC/xb.shtml',
    # 'http://www.weather.com.cn/textFC/xn.shtml
    for url in urls:
        get_temperature(url)
        time.sleep(2)

    SORTED_TEMPERATURE_LIST = sorted(TEMPERATURE_LIST, key=lambda x: int(x["min"]), reverse=True)
    TOP20_TEMPERATURE_LIST = SORTED_TEMPERATURE_LIST[0:20]
    print(TOP20_TEMPERATURE_LIST)
    TOP20_CITY_LIST = []
    TOP20_MIN_LIST = []
    for city_min in TOP20_TEMPERATURE_LIST:
        TOP20_CITY_LIST.append(city_min['city'])
        TOP20_MIN_LIST.append(city_min['min'])
    # #获取
    # 排序问题等到后续解决
    echart = Echart(u'全国最高温度排名', u'知了课堂贡献')
    bar = Bar(u'最高温度', TOP20_MIN_LIST)
    axis = Axis('category', 'bottom', data=TOP20_CITY_LIST)
    echart.use(bar)
    echart.use(axis)
    echart.plot()
Пример #10
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']))
Пример #11
0
def main():
    # target_urls = ['http://www.weather.com.cn/textFC/hb.shtml',
    #                'http://www.weather.com.cn/textFC/db.shtml',
    #                'http://www.weather.com.cn/textFC/hd.shtml',
    #                'http://www.weather.com.cn/textFC/hz.shtml',
    #                'http://www.weather.com.cn/textFC/hn.shtml',
    #                'http://www.weather.com.cn/textFC/xb.shtml',
    #                'http://www.weather.com.cn/textFC/xn.shtml']
    #
    # all_data = get_temperature(target_urls)
    # print(all_data)
    # 将数据保存到文件
    # with open('temperature.json', 'w', encoding='utf-8') as fw:
    #     fw.write(json.dumps(all_data))

    # 从文件中读取数据
    with open('temperature.json', 'r') as fr:
        all_data = json.loads(fr.read())
    # print(all_data)

    # 重新构造list结构
    temp_city_list = []
    for data in all_data:
        provence = data['provence']
        city_list = data['city_list']
        for city in city_list:
            city['city'] = '%s-%s' % (provence, city['city'])
            temp_city_list.append(city)
    print(temp_city_list)

    # 按照最高温度排序
    sort_max_temp_list = sorted(
        temp_city_list, key=lambda t: int(t.__getitem__('max_temperature')))
    # 按照最低温度排序
    sort_min_temp_list = sorted(
        temp_city_list, key=lambda t: int(t.__getitem__('min_temperature')))
    print(sort_max_temp_list)
    print(sort_min_temp_list)

    # 获取温度最高的10条数据
    top10_max = sort_max_temp_list[-10:]
    top10_max_city = []
    top10_max_temp = []
    print(top10_max)
    for item in top10_max:
        top10_max_city.append(item['city'])
        top10_max_temp.append(item['max_temperature'])

    # 获取温度最低的10条数据
    top10_min = sort_min_temp_list[:10]

    # 使用第三方Echarts库在浏览器中输出图形统计界面
    echart = Echart(u'全国温度统计')
    bar = Bar(u'最高温度', top10_max_temp)
    axis = Axis('category', 'bottom', data=top10_max_city)
    echart.use(bar)
    echart.use(axis)
    echart.plot()
Пример #12
0
Файл: app.py Проект: bonfy/feb
    def bar():
        # set bar color
        color = dict(color='#EE5500')

        chart = Echart('GDP', 'This is a fake chart')
        chart.use(Bar('China', [2, 3, 4, 5], itemStyle=dict(normal=color)))
        chart.use(Legend(['GDP']))
        chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan',
                                                   'Feb']))
        return jsonify(chart.json)
Пример #13
0
    def xx(self, data):
        _PR = PR.getInstance()

        chart = Echart('GDP', 'This is a fake chart')
        chart.use(Bar('China', [2, 3, 4, 5]))
        chart.use(Legend(['GDP']))
        chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan',
                                                   'Feb']))
        _chart = chart.json
        print(_chart)
        _chart["tooltip"] = {}
        _PR.setResult(_chart)
        return _PR.getPRBytes()
Пример #14
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()
Пример #15
0
def test_axis():
    chart = Echart('Axis', 'Proportion of Browser')
    assert not chart.json['xAxis'] and not chart.json['yAxis']
    chart.use(Axis('category', 'bottom', 'proportion', inverse=True))
    assert chart.json['xAxis']
    chart.use(Axis('category', 'left', 'proportion', inverse=True))
    assert chart.json['yAxis']
    map(repr, chart.x_axis)
Пример #16
0
def data_visualization(temperature_list):
    top20_temperature_list = sorted(
        temperature_list, lambda x, y: cmp(int(x['min']), int(y['min'])))[0:20]
    city20_list = []
    min20_list = []
    for city_min in top20_temperature_list:
        city20_list.append(city_min['city'])
        min20_list.append(city_min['min'])

    echart_show = Echart(u'全国最低温度排名', u'小白打酱油提供', u'这是气温排名')
    bar = Bar(u'最低温度', min20_list)
    axis = Axis('category', 'bottom', data=city20_list)
    echart_show.use(bar)
    echart_show.use(axis)
    echart_show.plot()
Пример #17
0
    def xx(self, data):
        _PR = PR.getInstance()

        chart = Echart('GDP', 'This is a fake chart')
        chart.use(Bar('China', [2, 3, 4, 5]))
        chart.use(Legend(['GDP']))
        chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan', 'Feb']))
        _chart = chart.json
        print(_chart)
        _chart["tooltip"] = {}
        _PR.setResult(_chart)
        return _PR.getPRBytes()
Пример #18
0
Файл: app.py Проект: 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)
Пример #19
0
def main():
    urls = [
        'http://www.weather.com.cn/textFC/hb.shtml',
        'http://www.weather.com.cn/textFC/db.shtml',
        'http://www.weather.com.cn/textFC/hd.shtml',
        'http://www.weather.com.cn/textFC/hz.shtml',
        'http://www.weather.com.cn/textFC/hn.shtml',
        'http://www.weather.com.cn/textFC/xb.shtml',
        'http://www.weather.com.cn/textFC/xn.shtml',
    ]
    for url in urls:
        get_temperature(url)
        time.sleep(2)

    echarts = Echart(u'温度排名')
    bar_x = Bar(u'最低温度', MIN_LIST)
    bar_y = Bar(u'最高温度', MAX_LIST)
    axis = Axis('category', 'bottom', data=CITY_LIST)
    echarts.use(bar_x)
    echarts.use(bar_y)
    echarts.use(axis)
    echarts.plot()
Пример #20
0
    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()
Пример #21
0
def main():
    urls=['http://www.weather.com.cn/textFC/hb.shtml',
          'http://www.weather.com.cn/textFC/db.shtml',
          'http://www.weather.com.cn/textFC/hd.shtml']
    for url in urls:
        get_temperature(url)

    #top10_max=max_list[0:10]
    #top10_cit=city_list[0:10]
    sorted_temprature_list=sorted(temperature_list,lambda x,y:cmp(int(x['max']),int(y['max'])))
    top10_temprature_list=sorted_temprature_list[0:8]
    top10_city_list=[]
    top10_max_list=[]
    for city_max in top10_temprature_list:
        top10_city_list.append(city_max['city'])
        top10_max_list.append(city_max['max'])
        print city_max['city'],city_max['max']

    echart=Echart(u'全国最高温度',u'3.19号')
    bar=Bar(u'最高温度',top10_max_list)
    axis=Axis('category','bottom',data=top10_city_list)
    echart.use(bar)
    echart.use(axis)
    echart.plot()
Пример #22
0
def main():
    urls = ['http://www.weather.com.cn/textFC/hb.shtml',
            'http://www.weather.com.cn/textFC/db.shtml',
            'http://www.weather.com.cn/textFC/hd.shtml',
            'http://www.weather.com.cn/textFC/hz.shtml',
            'http://www.weather.com.cn/textFC/hn.shtml',
            'http://www.weather.com.cn/textFC/xb.shtml',
            'http://www.weather.com.cn/textFC/xn.shtml']
    for url in urls:
        get_temperature(url)
        time.sleep(2)

    TOP20_MIN_LIST = MINTEMP_LIST[0:20]
    TOP20_CITY_LIST = CITY_LIST[0:20]
    print(TOP20_CITY_LIST)

    echart = Echart('全国最低温度统计', 'Author: AlexZ33')
    bar = Bar('最低温度', TOP20_MIN_LIST)
    axis = Axis('category', 'bottom', data = TOP20_CITY_LIST)

    echart.use(bar)
    echart.use(axis)
    # echart.use(Legend(['℃']))
    echart.plot()
Пример #23
0
itchat.login()

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"]
Пример #24
0
# html = open(html_path,'w')
# line = 0
# for s in lines:
# 	line = line + 1
# 	if line==32:
# 		html.write('data: %s\n' % valueList)
# 	if  line==26:
# 		html.write('data: [')
# 		for str in nameList:
# 			html.write('\"%s\",' % str.encode('utf-8'))
# 		html.write(']\n')
# 	else:
# 		html.write(s)

# 用echart画图
chart = Echart(u'WeChat 好友省份分布图', 'data from xuqidong')
chart.use(Bar('China', valueList))
chart.use(Legend(['GDP']))
chart.use(Axis('category', 'left', data=nameList))
chart.plot()

# 获取好友列表
# 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
Пример #25
0
    sex = friend['Sex']
    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()
Пример #26
0
def dataStatistics(request):
    chart = Echart('GDP', 'This is a fake chart')
    chart.use(Bar('China', [2, 3, 4, 5]))
    chart.use(Legend(['GDP']))
    chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan', 'Feb']))
    return render(request, 'dataStatistics.html', locals())
Пример #27
0
import json
from echarts import Echart, Legend, Bar, Axis
with open(u'温度数据.json', 'r') as fr:
    data = json.load(fr, encoding='utf-8')

city_list = []
min_list = []
sorted_list = sorted(data,
                     lambda x, y: cmp(int(x['C_min']), int(y['C_min'])),
                     reverse=True)
for item in sorted_list[:20]:
    city_list.append(item[u'城市'])
    min_list.append(item['C_min'])
    #print item[u'省份'], item[u'城市'],item['C_min']
chart = Echart(u'全国TOP20温度', u'全国温度最高的前20个市')
chart.use(Bar(u'temp', min_list))
chart.use(Axis('category', 'bottom', 'map', city_list))
chart.plot()
Пример #28
0
    @property
    def json(self):
        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)
Пример #29
0
def test_legend():
    chart = Echart('Legend', 'Demo for legend')
    chart.use(Legend(['Item1 Title'], 'vertical', show=True))

    assert chart.json['legend']['data']
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"]
Пример #31
0
con = sqlite3.connect("database.sqlite", isolation_level=None)
cur = con.cursor()
age_set = {}
name = '%iniesta%'
#today = date.today()
cur.execute(
    'select short_passing,long_passing,strength,vision,dribbling,balance,positioning from Player inner join Player_Attributes on Player.player_api_id = Player_Attributes.player_api_id where player_name like ? group by player_name',
    (name, ))

i = list(cur.fetchone())
iniesta_attrib = {
    "short_passing": i[0],
    "long_passing": i[1],
    "strength": i[2],
    "vision": i[3],
    "dribbling": i[4],
    "balance": i[5],
    "positioning": i[6]
}
#labels = ["short_passing","long_passing","strength","vision","dribbling","balance","positioning"]
p_val = list(iniesta_attrib.values())
p_key = list(iniesta_attrib.keys())
print p_val
xv = plt.DataFrame({'val': p_val, 'keyt': p_key})
chart = Echart('Andres Iniesta', 'Mid Fielder Attributes')
#chart.use(Bar('Out of 100', p_val))
chart.use(Line('Out of 100', p_val))
chart.use(Legend(['Andres Iniesta']))
chart.use(Axis('category', 'bottom', data=p_key))
chart.plot()
Пример #32
0
def test_toolbox():
    chart = Echart('Toolbox', 'Tooltip for echarts')
    chart.use(Toolbox('horizontal', show=True))

    assert chart.json['toolbox']['orient'] == 'horizontal'
    assert chart.json['toolbox']['show'] == True
Пример #33
0
def test_tooltip():
    chart = Echart('Tooltip', 'Tooltip for echarts')
    chart.use(Tooltip('axis', show=True))

    assert chart.json['tooltip']['trigger'] == 'axis'
    assert chart.json['tooltip']['show'] == True
Пример #34
0
def test_datastructure():
    for DS in VERSION_ALL:
        chart = Echart('GDP', 'This is a fake chart')
        chart.use(DS('2014', [2, 3, 4, 5], zlevel=0))
        assert len(chart.json['series']) > 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 u"男性好友:%.2f%%" % (float(male) / total * 100)
print u"女性好友:%.2f%%" % (float(female) / total * 100)
print u"未填性别:%.2f%%" % (float(other) / total * 100)

# 使用echarts,加上这段
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()
Пример #36
0
def test_extra():
    str(Echart.__base__())
Пример #37
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()
Пример #38
0
def viewableData(dataJson):
    statisticInfo = json.loads(dataJson)
    # 拆分Json文件,拆成多个列表
    # 网站列表,最大rtt时间,平均rtt时间,丢包率
    hostList, maxList, avgList, dropRateList = [], [], [], []
    for i in statisticInfo:
        hostList.append(i)
        maxList.append(statisticInfo[i]['max_rtt'])
        avgList.append(statisticInfo[i]['median_rtt'])
        dropRateList.append(float(statisticInfo[i]['drop_rate'][:-1]))

    # 对网页进行初始化处理
    chart = Echart(title='ping结果统计', width='auto', height='auto')

    # 设置三条数据
    chart.use(Bar('maxList', maxList, tpye='vertical'))
    chart.use(Bar('avgList', avgList, tpye='vertical'))
    chart.use(Bar('dropRateList', dropRateList, tpye='certical'))

    # 设置y轴
    chart.use(
        Axis('category', 'left', data=hostList, axisLabel={'interval': 0}))

    # 启用显示
    chart.use(Tooltip(trigger='axis'))
    # 启用图标
    chart.use(
        Legend(['maxList', 'avgList', 'dropRateList'],
               position=('center', 'top')))
    # 启用工具栏
    feature = {
        'dataZoom': {
            'show': True,
            'title': {
                'dataZoom': '区域缩放',
                'dataZoomReset': '区域缩放后退'
            }
        },
        'magicType': {
            'show': True,
            'type': ['line', 'bar', 'stack', 'tiled']
        },
        'restore': {
            'show': True,
            'title': '还原'
        }
    }
    # 开启工具盒子
    chart.use(Toolbox(feature=feature, orient='vertical', show=True))

    # 展示可视化数据
    chart.plot()

    # 存储html
    chart.save(os.getcwd() + '/', 'ping可视化数据')
Пример #39
0
    print i
    if sex == 1:
        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"]
Пример #40
0
 def bar():
     chart = Echart('GDP', 'This is a fake chart')
     chart.use(Bar('China', [2, 3, 4, 5]))
     chart.use(Legend(['GDP']))
     chart.use(Axis('category', 'bottom', data=['Nov', 'Dec', 'Jan', 'Feb']))
     return jsonify(chart.json)