Ejemplo n.º 1
0
def test_custom_template_for_chart():
    data = [{
        'name': '衬衫',
        'value': 5
    }, {
        'name': '羊毛衫',
        'value': 20
    }, {
        'name': '雪纺衫',
        'value': 36
    }]

    configure(echarts_template_dir='.')

    online()

    data1 = {'衬衫': '34', '羊毛衫': 45, '雪纺衫': 40}
    names, values = Bar.cast(data)
    names1, values1 = Bar.cast(data1)
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", names, values, is_stack=True)
    bar.add("商家B", names1, values1, is_stack=True)
    bar.render(path='new_version_bar.html')
    with codecs.open('new_version_bar.html', 'r', 'utf-8') as f:
        actual_content = f.read()
        assert "</html>" in actual_content
Ejemplo n.º 2
0
def draw_DateBar(comments):
    print("正在处理观众评论数量与日期的关系......")
    time = pd.to_datetime(comments['startTime'])  # 获取评论时间并转换为标准日期格式
    time = time.apply(lambda x: judgeTime(x, startTime_tag)
                      )  # 将2019.2.4号之前的数据汇总到2.4 统一标识为电影上映前影评数据
    timeData = []
    for t in time:
        if pd.isnull(t) == False:  # 获取评论日期(删除具体时间)并记录
            t = str(t)  # 转换为字符串以便分割
            date = t.split(' ')[0]
            timeData.append(date)

    data = Counter(timeData).most_common()  # 记录相应日期对应的评论数
    data = sorted(data, key=lambda data: data[0])  # 使用lambda表达式对数据按日期进行排序

    bar = Bar('《流浪地球》观众评论数量与日期的关系', '数据来源:猫眼电影 数据分析:16124278-王浩',
              **style_others.init_style)  # 初始化柱状图
    attr, value = bar.cast(data)  # 传值
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 43000],
            visual_text_color='black',
            is_more_utils=True,
            is_label_show=True)  # 加入数据和其它参数
    bar.render('./output/观众评论日期-柱状图.html')  # 渲染
    print("观众评论数量与日期的关系已完成!!!")
Ejemplo n.º 3
0
def create_money(data, title):
    page = Page()
    style = Style(width=1000, height=500, background_color='#c4ccd3')
    money_chart = Bar(title, **style.init_style)
    attr, value = money_chart.cast(data)
    money_chart.add("", attr, value, is_label_show=True)
    page.add(money_chart)
    return page
Ejemplo n.º 4
0
def test_custom_template_for_chart():
    data = [
        {"name": "衬衫", "value": 5},
        {"name": "羊毛衫", "value": 20},
        {"name": "雪纺衫", "value": 36},
    ]

    configure(echarts_template_dir=".")

    data1 = {"衬衫": "34", "羊毛衫": 45, "雪纺衫": 40}
    names, values = Bar.cast(data)
    names1, values1 = Bar.cast(data1)
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", names, values, is_stack=True)
    bar.add("商家B", names1, values1, is_stack=True)
    bar.render(path="new_version_bar.html")
    with codecs.open("new_version_bar.html", "r", "utf-8") as f:
        actual_content = f.read()
        assert "</html>" in actual_content
Ejemplo n.º 5
0
def render():
    global comment_text
    with open('jay.csv', mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows[1:]:
            if row.count(',') != 3:
                continue
            elements = row.split(',')
            user = elements[0]
            date = elements[1]
            if '2019' not in date:
                continue
            like = elements[2]
            comment = elements[3]
            if '2019-09-14' in date:
                dates.append('2019-09-14')
            elif '2019-09-15' in date:
                dates.append('2019-09-15')
            elif '2019-09-16 0' in date or '2019-09-16 1' in date or '2019-09-16 20' in date or '2019-09-16 21' in date:
                dates.append('2019-09-16 0-21')
            elif '2019-09-18' in date:
                continue
            else:
                dates.append(date)
            comment_text += comment

    with open("comment_text.txt", "w", encoding='utf-8') as f:
        f.write(comment_text)

    date_data = Counter(dates).most_common()
    # 按日期进行排序
    date_data = sorted(date_data)
    # print(data)

    # 根据评分数据生成柱状图
    bar = Bar('评价人数走势图',
              '数据来源:不正经程序员-采集自QQ音乐',
              title_pos='center',
              width=800,
              height=600)
    attr, value = bar.cast(date_data)
    bar.add('',
            attr,
            value,
            is_visualmap=False,
            visual_range=[0, 3500],
            visual_text_color='#fff',
            is_more_utils=True,
            xaxis_interval=0,
            xaxis_rotate=30,
            is_label_show=True,
            xaxis_label_textsize=8,
            label_text_size=8)

    bar.render('picture\评价人数走势图.html')
Ejemplo n.º 6
0
def render():
    cities = []
    with open('comments.txt', mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows:
            print(row)
            if row.strip() != '' and row.find('$'):
                city = row.split('$')[1]
                if city != '':  # 去掉城市名为空的值
                    cities.append(city)

        # 对城市数据和坐标文件中的地名进行处理
    handle(cities)

    # 统计每个城市出现的次数
    # data = []
    # for city in set(cities):
    #     data.append((city, cities.count(city)))
    data = Counter(cities).most_common()  # 使用Counter类统计出现的次数,并转换为元组列表

    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color="#404a59")

    geo = Geo('《毒液》观众位置分布', '数据来源:猫眼-Ryan采集', **style.init_style)
    attr, value = geo.cast(data)
    geo.add('',
            attr,
            value,
            visual_range=[0, 3500],
            visual_text_color='#fff',
            symbol_size=15,
            is_visualmap=True,
            is_piecewise=True,
            visual_split_number=10)
    geo.render('粉丝位置分布-地理坐标图.html')

    data_top20 = Counter(cities).most_common(20)
    bar = Bar('《毒液》观众来源排行TOP20',
              '数据来源:猫眼-Ryan采集',
              title_pos='center',
              width=1200,
              height=600)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 3500],
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('观众来源排行-柱状图.html')
Ejemplo n.º 7
0
 def bartest(self):
     from pyecharts import Bar
     bar = Bar('等级分布条形图', self.ftitle)
     # 利用自带的解析方法把列表解析成2个关联列表
     key, value = bar.cast(self.bardata)
     # is_datazoom_show = 参数是用来显示下滑筛选块的,默认假
     # is_label_show = 参数用来显示数值,默认假
     bar.add('等级分布', key, value, is_datazoom_show=False, is_label_show=True)
     # bar.show_config()
     bar.render(r"pic\等级分布条形图.html")
     print('成功输出Bar测试网页')
Ejemplo n.º 8
0
def render():

    city_counts = df.groupby("cityName").size()
    new_citys = handle(city_counts.index)

    tuple_city = list(city_counts.items())

    attr_values = []
    for item in tuple_city:
        #print(item[0],end=' ')
        if item[0] in new_citys:
            attr_values.append(item)

    # 定义样式
    style = Style(title_color='#fff',
                  title_pos='center',
                  width=1200,
                  height=600,
                  background_color='#404a59',
                  subtitle_color='#fff')
    #
    # 根据城市数据生成地理坐标图
    geo = Geo('《无双》评星人位置分布', '图表来源:CSDN博客-梦想橡皮擦', **style.init_style)
    attr, value = geo.cast(attr_values)

    geo.add('',
            attr,
            value,
            visual_range=[0, 2500],
            type="scatter",
            visual_text_color='#fff',
            symbol_size=10,
            is_visualmap=True,
            visual_split_number=10)
    geo.render('评星人位置分布-地理坐标图.html')

    # 根据城市数据生成柱状图

    city_sorted = city_counts.sort_values(ascending=False).head(20)

    bar = Bar("《无双》评星人来源排行TOP20", "CSDN博客-梦想橡皮擦", **style.init_style)
    attr, value = bar.cast(list(city_sorted.items()))
    bar.add("",
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 2500],
            visual_text_color='#fff',
            label_color='#fff',
            xaxis_label_textcolor='#fff',
            yaxis_label_textcolor='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render("评星人来源排行-柱状图.html")
Ejemplo n.º 9
0
 def _salary_show(self):
     bar = Bar("薪资统计", title_pos='center', width=1200, height=500)
     attr, value = bar.cast(self.g.salary_data)
     bar.add("",
             attr,
             value,
             xaxis_interval=0,
             xaxis_rotate=30,
             yaxis_rotate=30,
             is_more_utils=True)
     return bar.render_embed()
Ejemplo n.º 10
0
def render():
    # 获取所有城市信息
    cities = []
    with open('comments.txt', mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows:
            try:
                city = row.split(',')[2]
            except:
                continue
            if city != '':
                cities.append(city)

    # 对城市数据和坐标文件中的地名进行处理
    handle(cities)

    # 统计每个城市出现的次数
    # data = []
    # for city in set(cities):
    #     data.append((city, cities.count(city)))
    data = Counter(cities).most_common()

    # 根据城市数据生成地理坐标图
    geo = Geo(
        "电影《哪吒》用户位置分布及热度",
        "数据来源:猫眼",
        title_color="#FFF",
        title_pos="center",
        width=1200,
        height=600,
        background_color="#404a59",
    )
    attr, value = geo.cast(data)
    geo.add(
        "",
        attr,
        value,
        visual_range=[0, 6500],
        visual_text_color="#fff",
        symbol_size=15,
        is_visualmap=True,
    )
    geo.render('粉丝位置分布.html')

    # 根据城市数据生成柱状图
    cities_top20 = Counter(cities).most_common(20)  # 返回出现次数最多的20条
    bar = Bar("《哪吒》粉丝来源排行榜",
              '数据来源:猫眼',
              title_pos='center',
              width=1200,
              height=600)
    attr, value = bar.cast(cities_top20)
    bar.add("", attr, value)
    bar.render('粉丝来源排行榜-柱状图.html')
Ejemplo n.º 11
0
def caculate_mi_list(dir_path):
    files = common.get_filelist(dir_path)
    res = _caculate_mi_list(files[3], files[0:10])
    data_a, data_b = Bar.cast(res)
    print data_a
    print data_b
    bar = Line("甜甜的实验", "二哥出品")
    bar.use_theme('vintage')
    bar.add("数据", data_a, data_b)
    bar.render()
    return
Ejemplo n.º 12
0
def render():
    # 获取所有城市
    cities = []
    with open('friends.json', mode='r') as f:
        read_data = f.read()
        json_data = json.loads(read_data)
        for temp in json_data:
            city = str(temp['City'])
            if city != '':  # 去掉城市名为空的值
                cities.append(city)
    # 对城市数据和坐标文件中的地名进行处理
    # handle(cities)
    # 统计每个城市出现的次数
    data = Counter(cities).most_common()  # 使用Counter类统计出现的次数,并转换为元组列表
    print(data)
    # 根据城市数据生成地理坐标图
    geo = Geo('好友位置分布',
              '',
              title_color='#fff',
              title_pos='center',
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    # print(attr, value)
    # geo.add('', attr, value, visual_range=[0, 500],
    #         visual_text_color='#fff', symbol_size=15,
    #         is_visualmap=True, is_piecewise=True)
    try:
        geo.add('',
                attr,
                value,
                visual_range=[0, 500],
                visual_text_color='#fff',
                symbol_size=15,
                is_visualmap=True,
                is_piecewise=True)
    except ValueError:
        pass
    geo.render('好友位置分布.html')
    # 根据城市数据生成柱状图
    data_top20 = Counter(cities).most_common(20)  # 返回出现次数最多的20条
    bar = Bar('好友所在城市TOP20', '', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('好友所在城市TOP20.html')
Ejemplo n.º 13
0
def data_bar():
    data = []
    with open('haiwangtop20.txt', 'r', encoding='utf-8') as f:
        lines = f.readlines()
    for item in lines:
        cityinfo = item.split()
        print(cityinfo[0], cityinfo[1])
        data.append((cityinfo[0], cityinfo[1]))

    bar = Bar("《海王》评论数前20")
    attr, value = bar.cast(data)
    bar.add("海王》评论数前20", attr, value,is_label_show=True,xaxis_interval=0)
    bar.render('top20.html')
Ejemplo n.º 14
0
def chart():
    data = {
        '张三': 123.3,
        '李四': 66.8,
        '王五': 86.4,
        '杨六': 77.9,
        'ji': 46.3,
        'pp': 110.4
    }
    bar = Bar()
    v1, v2 = bar.cast(data)
    bar.add('weight', v1, v2)
    return render_template('simple_chart.html', chart=bar)
Ejemplo n.º 15
0
def gender():
    cities = []
    with open('E:/spiderproject/maoyanMovies_comments/comments.txt',
              'r',
              encoding='utf-8') as f:
        rows = f.readlines()
        try:
            for row in rows:
                city = row.split(',')[1]
                if city != '':
                    cities.append(city)
                #print(city)
        except Exception as e:
            print(e)

    handle(cities)
    data = Counter(cities).most_common()
    style = Style(title_color='#fff',
                  title_pos='center',
                  width=1200,
                  height=600,
                  background_color='#404a59')
    geo = Geo('《毒液》观众位置分布', '数据来源:猫眼-Ryan采集', **style.init_style)
    attr, value = geo.cast(data)
    geo.add('',
            attr,
            value,
            visual_range=[0, 1000],
            visual_text_color='#fff',
            symbol_size=15,
            is_visualmap=True,
            is_piecewise=False,
            visual_split_number=10)
    geo.render('观众位置分布-地理坐标图.html')

    data_top20 = Counter(cities).most_common(20)
    bar = Bar('《毒液》观众来源排行TOP20',
              '数据来源:猫眼-Ryan采集',
              title_pos='center',
              width=1200,
              height=600)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 3500],
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('观众来源排行-柱状图.html')
Ejemplo n.º 16
0
def test_custom_template_for_chart():
    data = [{
        'name': '衬衫',
        'value': 5
    }, {
        'name': '羊毛衫',
        'value': 20
    }, {
        'name': '雪纺衫',
        'value': 36
    }]

    configure(echarts_template_dir='.')

    data1 = {'衬衫': '34', '羊毛衫': 45, '雪纺衫': 40}
    names, values = Bar.cast(data)
    names1, values1 = Bar.cast(data1)
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", names, values, is_stack=True)
    bar.add("商家B", names1, values1, is_stack=True)
    bar.render(path='new_version_bar.html')
    with codecs.open('new_version_bar.html', 'r', 'utf-8') as f:
        actual_content = f.read()
        assert "</html>" in actual_content
Ejemplo n.º 17
0
def render():
    # 获取所有城市
    cities = []
    with open('friends.txt', mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows:
            city = row.split(',')[4]
            if city != '':  # 去掉城市名为空的值
                cities.append(city)

    # 对城市数据和坐标文件中的地名进行处理
    handle(cities)

    # 统计每个城市出现的次数
    data = Counter(cities).most_common()  # 使用Counter类统计出现的次数,并转换为元组列表
    print(data)

    # 根据城市数据生成地理坐标图
    geo = Geo('好友位置分布',
              '',
              title_color='#fff',
              title_pos='center',
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    geo.add('',
            attr,
            value,
            visual_range=[0, 500],
            visual_text_color='#fff',
            symbol_size=15,
            is_visualmap=True,
            is_piecewise=True)
    geo.render('好友位置分布.html')

    # 根据城市数据生成柱状图
    data_top20 = Counter(cities).most_common(20)  # 返回出现次数最多的20条
    bar = Bar('好友所在城市TOP20', '', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('好友所在城市TOP20.html')
Ejemplo n.º 18
0
def draw_bar(comments):
    print("正在处理观众地域排行榜单......")
    data_top20 = Counter(comments['cityName']).most_common(20)  # 筛选出数据量前二十的城市
    bar = Bar('《流浪地球》观众地域排行榜单', '数据来源:猫眼电影 数据分析:16124278-王浩',
              **style_others.init_style)  # 初始化柱状图
    attr, value = bar.cast(data_top20)  # 传值
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 16000],
            visual_text_color='black',
            is_more_utils=True,
            is_label_show=True)  # 加入数据与其它参数
    bar.render('./output/观众地域排行榜单-柱状图.html')  # 渲染
    print("观众地域排行榜单已完成!!!")
Ejemplo n.º 19
0
def render():
    # 获取所有城市
    """ 安装地图文件包
pip install echarts-china-provinces-pypkg # 中国省、市、县、区地图
pip install echarts-china-cities-pypkg
pip install echarts-china-counties-pypkg
pip install echarts-china-misc-pypkg 
pip install echarts-countries-pypkg # 全球国家地图
pip install echarts-united-kingdom-pypkg
    """
    # 导入Counter类,用于统计值出现的次数
    from collections import Counter
    # 导入Geo组件,用于生成地理坐标类图
    from pyecharts import Geo
    # 导入Bar组件,用于生成柱状图
    from pyecharts import Bar
    cities = []
    with open(friends_data, mode='r', encoding='utf-8') as f:
        rows = f.readlines()
        for row in rows:
            city = row.split(',')[4]
            if city != '':  # 去掉城市名为空的值
                cities.append(city)

    # 对城市数据和坐标文件中的地名进行处理
    handle(cities)

    # 统计每个城市出现的次数
    data = Counter(cities).most_common()  # 使用Counter类统计出现的次数,并转换为元组列表

    # 根据城市数据生成地理坐标图
    geo = Geo('好友位置分布', '', title_color='#fff', title_pos='center', width=1200, height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    geo.add('', attr, value, visual_range=[0, 100],
            visual_text_color='#fff', symbol_size=15,
            is_visualmap=True, is_piecewise=True)
    geo.render(current_dir+'/好友位置分布.html')

    # 根据城市数据生成柱状图
    data_top20 = Counter(cities).most_common(20)  # 返回出现次数最多的20条
    bar = Bar('好友所在城市TOP20', '', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data_top20)
    bar.add('', attr, value, is_visualmap=True, visual_text_color='#fff', is_more_utils=True,
            is_label_show=True)
    bar.render(current_dir+'/好友所在城市TOP20.html')
Ejemplo n.º 20
0
def draw_TimeBar(comments):
    time = comments['startTime']
    timeData = []
    for t in time:
        if pd.isnull(t) == False:
            time = t.split(' ')[1]
            hour = time.split(':')[0]
            timeData.append(hour)
 
    data = Counter(timeData).most_common()
    data = sorted(data, key=lambda data : data[0])    
    
    bar = Bar('《流浪地球》观众评论数量与时间的关系', '数据来源:猫眼电影 数据分析:公众号【谭某人】', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data)
    bar.add('', attr, value, is_visualmap=True, visual_range=[0, 3500], visual_text_color='#fff', is_more_utils=True, is_label_show=True)
    bar.render('./观众评论时间-柱状图.html')
    print("观众评论数量与时间的关系已完成")
Ejemplo n.º 21
0
def draw_bar(comments):
    data_top20 = Counter(comments['cityName']).most_common(20)
    bar = Bar('《毒液》观众来源排行TOP20',
              '数据来源:猫眼-Ryan采集',
              title_pos='center',
              width=1200,
              height=600)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 3500],
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('./观众来源排行-柱状图.html')
    print("success")
Ejemplo n.º 22
0
def draw_bar(comments):
    data_top20 = Counter(comments['cityName']).most_common(20)
    bar = Bar('《Avengers:Endgame》观众地域排行榜单',
              '数据来源:猫眼电影',
              title_pos='center',
              width=1450,
              height=725)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 4500],
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('./观众地域排行榜单.html')
    print("观众地域排行榜单已完成")
Ejemplo n.º 23
0
def hot_city():
    data = []
    cities = []
    city_counts = {}
    with open('data/comments.txt', 'r', encoding='utf-8') as f:
        rows = f.readlines()
        try:
            for row in rows:
                if row != '':
                    city = row.split(',')[1]
                if city != '':
                    cities.append(city)
                    if not city_counts.get(city):
                        city_counts[city] = 1
                    else:
                        city_counts[city] += 1
        except Exception as e:
            print(e)
    for k, v in city_counts.items():
        data.append((k, v))
    # print(data)
    # geo = Geo('Audiences distribution', 'Data Source: m.maoyan.com', title_color="#fff", title_pos="center", width=1000,
    #             height=600, background_color='#404a59')
    # attr, value = geo.cast(data)
    # geo.add('', attr, value, visual_range=[0, 1000], visual_text_color='#fff', symbol_size=15, is_visualmap=True,
    #         is_piecewise=False, visual_split_number=10)
    # geo.render('output/audiences-distribution.html')

    top20_cities = Counter(cities).most_common(20)
    bar = Bar('Top20 cities of audiences',
              'Data Source: m.maoyan.com',
              title_pos='center',
              width=1200,
              height=600)
    attr, value = bar.cast(top20_cities)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_range=[0, 3500],
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('output/Audiences-source.html')
Ejemplo n.º 24
0
def location():
    cities = []
    with open('wechatfriends.txt', mode='r', encoding='utf-8') as f:
        rows2 = f.readlines()
        for i in rows2:
            city = i.split(',')[3]
            if '\u4e00' <= city <= '\u9fa5':  # 获取好友地区为中文的城市
                cities.append(city)
    data = Counter(cities).most_common()
    # for i in range(len())
    print(data)
    geo = Geo('好友位置分布',
              '',
              title_color='#fff',
              title_pos='center',
              width=1400,
              height=800,
              background_color='#404a59')
    # geo.add_coordinate('江北', 106.57,29.60)
    attr, value = geo.cast(data)
    geo.add('',
            attr,
            value,
            visual_range=[0, 40],
            visual_text_color='#fff',
            symbol_size=10,
            is_visualmap=True,
            is_piecewise=True,
            visual_split_number=8)
    geo.render('好友位置分布.html')
    # 生成柱状图
    data_top20 = Counter(cities).most_common(20)
    bar = Bar('好友所在城市top20', '', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data_top20)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('好友所在城市top20.html')
Ejemplo n.º 25
0
def create_city(cities):
    fc = []
    for v in cities:
        if v != '' and v != '海淀' and v != '延边':
            fc.append(v)
    # 统计每个城市出现的次数
    data = Counter(fc).most_common(5)  # 使用Counter类统计出现的次数,并转换为元组列表
    print(data)
    # 根据城市数据生成地理坐标图
    geo = Geo('好友位置分布',
              '',
              title_color='#fff',
              title_pos='center',
              width=1200,
              height=600,
              background_color='#404a59')
    attr, value = geo.cast(data)
    print(attr)
    print(value)
    geo.add('',
            attr,
            value,
            visual_text_color='#fff',
            symbol_size=15,
            is_visualmap=True,
            is_piecewise=True)
    geo.render('好友位置分布.html')
    # 根据城市数据生成柱状图
    data_top10 = Counter(fc).most_common(10)  # 返回出现次数最多的20条
    bar = Bar('好友所在城市TOP10', '', title_pos='center', width=1200, height=600)
    attr, value = bar.cast(data_top10)
    bar.add('',
            attr,
            value,
            is_visualmap=True,
            visual_text_color='#fff',
            is_more_utils=True,
            is_label_show=True)
    bar.render('好友所在城市TOP10.html')
Ejemplo n.º 26
0
def create_Bar_charts(data, title):
    '''柱状图'''

    page = Page()

    style = Style(
        width=800,
        height=600,
        title_pos="center",
    )

    chart = Bar(title, **style.init_style)
    attr, value = chart.cast(data)
    chart.add('',
              attr,
              value,
              mark_line=["average"],
              mark_point=["max", "min"],
              is_datazoom_show=True,
              datazoom_range=[50, 80])

    page.add(chart)
    return page
Ejemplo n.º 27
0
def test_base_cast_dict():
    adict = {"key": 1, "value": 2}
    keys, values = Bar.cast(adict)
    eq_(keys, ["key", "value"])
    eq_(values, [1, 2])
Ejemplo n.º 28
0
def test_base_cast_records():
    records = [{"key": 1}, {"value": 2}]
    keys, values = Bar.cast(records)
    eq_(keys, ["key", "value"])
    eq_(values, [1, 2])
Ejemplo n.º 29
0
from pyecharts import Style

# 定义样式
style = Style(title_color='#fff',
              title_pos='center',
              width=1000,
              height=600,
              background_color='#404a59',
              subtitle_color='#fff')

# 根据城市数据生成柱状图
city_counts = ct_datas.groupby("城市").size()
city_sorted = city_counts.sort_values(ascending=False).head(20)

bar = Bar("《流浪地球》评星人来源排行TOP20", "蜗牛行天下", **style.init_style)
attr, value = bar.cast(list(city_sorted.items()))
bar.add("",
        attr,
        value,
        is_visualmap=True,
        visual_range=[0, 2500],
        visual_text_color='#fff',
        label_color='#fff',
        xaxis_label_textcolor='#fff',
        yaxis_label_textcolor='#fff',
        is_more_utils=True,
        is_label_show=True)

# 保存可视化图片文件
bar.render("评星人来源排行-柱状图.html")
# 图像可视化
Ejemplo n.º 30
0
@itchat.msg_register(TEXT, isGroupChat=True)
def statistics(msg):
    if msg['FromUserName'] == groupID:
        print('{}发言了:{}'.format(msg['ActualNickName'], msg['Text']))
        talkCounter[msg['ActualNickName']] += 1
        print(talkCounter)

if __name__ == '__main__':s
    itchat.auto_login(hotReload=True)
    groupName = '啊哈'
    groupID = itchat.search_chatrooms(name=groupName)[0]['UserName']

    talkCounter = Counter()
    beginTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    itchat.run()
    endTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    duration = '统计自 {} 到 {} 时间段内'.format(beginTime, endTime)

    bar = Bar(title='{}群活跃度表'.format(groupName), subtitle=duration, width=1200, height=600, title_pos='left')
    attr, value = bar.cast(talkCounter.most_common(100))
    bar.add(
        '', attr, value,
        xaxis_name='昵称',
        yaxis_name='发言活跃度',
        is_label_show = True,
        is_datazoom_show = True,
        datazoom_type = 'both',
        xaxis_name_pos = 'end'
    )
    bar.render('./{}发言活跃度.html'.format(groupName))
# 导入Counter类,用于统计值出现的次数
from collections import Counter
from pyecharts import Bar

# 获取备注名
remarkNames = []
with open('friends.txt', mode='r', encoding='utf-8') as f:
    rows = f.readlines()
    for row in rows:
        remarkName = row.split(',')[1]
        if remarkName != '':
            remarkNames.append(remarkName)

# 设置分词
words = [
    x for x in jieba.cut(str(remarkNames), cut_all=False)
    if x not in ['-', ',', '(', ')', '(', ')', ' ', "'"]
]  # 排除短横线、逗号、空格、单引号
data_top10 = Counter(words).most_common(10)  # 返回出现次数最多的10条
print(data_top10)

bar = Bar('好友分类TOP10', '', title_pos='center', width=1200, height=600)
attr, value = bar.cast(data_top10)
bar.add('',
        attr,
        value,
        visual_range=[0, 200],
        is_visualmap=True,
        is_label_show=True)
bar.render('好友分类TOP10.html')
Ejemplo n.º 32
0
def test_base_cast_dict():
    adict = {"key": 1, "value": 2}
    keys, values = Bar.cast(adict)
    eq_(keys, ["key", "value"])
    eq_(values, [1, 2])
Ejemplo n.º 33
0
def test_base_cast_records():
    records = [{"key": 1}, {"value": 2}]
    keys, values = Bar.cast(records)
    eq_(keys, ["key", "value"])
    eq_(values, [1, 2])