コード例 #1
0
ファイル: analysis.py プロジェクト: xtuyaowu/Scrapy-Tieba
 def linetest(self):
     from pyecharts import Line
     line = Line('发帖时间分布折线图', self.ftitle)
     key, value = line.cast(self.linedata)
     line.add('发帖人数',
              key,
              value,
              is_label_show=True,
              is_fill=True,
              area_opacity=0.3,
              is_smooth=True)
     line.render(r'pic\发帖时间折线图.html')
     print("折线图测试成功输出")
コード例 #2
0
def draw_sentiment_pic(comments):
    print("正在处理观众情感曲线......")
    score = comments['score'].dropna()  # 获取观众评分
    data = Counter(score).most_common()  # 记录相应评分对应的的评论数
    data = sorted(data, key=lambda data: data[0])  # 使用lambda表达式对数据按评分进行排序
    line = Line('《流浪地球》观众情感曲线', '数据来源:猫眼电影 数据分析:16124278-王浩',
                **style_others.init_style)  # 初始化
    attr, value = line.cast(data)  # 传值

    for i, v in enumerate(attr):  # 将分数修改为整数便于渲染图上的展示
        attr[i] = v * 2

    line.add("",
             attr,
             value,
             is_smooth=True,
             is_more_utils=True,
             yaxis_max=380000,
             xaxis_max=10)  # 加入数据和其它参数
    line.render("./output/观众情感分析-曲线图.html")  # 渲染
    print("观众情感曲线已完成!!!")
コード例 #3
0
 def gen_line(city, times_prices):
     line = Line()
     times, prices = line.cast(times_prices)
     line.add(city, times, prices)
     return line
コード例 #4
0
    def time_distribution(self, times):
        # 计算v1,按小时统计,计算V2,按天统计
        date_hour = []
        date_day = []
        for time in times:
            dtime = datetime.datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
            date_hour.append(dtime.strftime('%m-%d|%H'))
            date_day.append(dtime.strftime('%m-%d'))

        # 按时间升序排序
        date_hour.sort()
        date_day.sort()
        # 不能用counter类,因为他会排序
        date_hour_dict = {}
        for date in date_hour:
            if date not in date_hour_dict:
                date_hour_dict[date] = 1
            else:
                date_hour_dict[date] += 1
        # print(date_hour_dict)
        # 每日总数
        date_day_dict = {}
        for date in date_day:
            if date not in date_day_dict:
                date_day_dict[date] = 1
            else:
                date_day_dict[date] += 1
        # print(date_day_dict)

        line_top = Line("评论时间(小时)折线图")
        attr1, v1 = line_top.cast(date_hour_dict)
        # print(attr)
        # print(v)
        line_top.add("时间(小时)",
                     attr1,
                     v1,
                     mark_point=['max'],
                     mark_line=['average'],
                     is_fill=True,
                     area_color="#FFCCCC",
                     area_opacity=0.3,
                     is_smooth=True,
                     is_datazoom_show=True,
                     datazoom_type="both",
                     datazoom_xaxis_index=[0, 1])
        # line.render(self.path + r'/time_line.html')
        line_bottom = Line("")
        attr2, v2 = line_bottom.cast(date_day_dict)
        line_bottom.add(
            "时间(天)",
            attr2,
            v2,
            legend_pos="60%",
            mark_point=["max", "min"],
            mark_line=["average"],
            # is_yaxis_inverse=True,
            xaxis_pos="top",
            is_datazoom_show=True)

        grid = Grid(width=1200, height=800)
        grid.add(line_top, grid_bottom='60%')
        grid.add(line_bottom, grid_top='50%')
        grid.render(self.path + r'/time_line.html')