可视化展示——界面展示&词云效果添加

界面展示

django界面 pyechart bootstrap

1.预测结果效果:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.词云效果添加;

在这里插入图片描述
代码:

##词云--------------------------------------
            # 年份列表
            file_years = 'choose_paper/data/years.txt'
            years = []
            with open(file_years,'r',encoding="utf-8") as f:
             for line in f.readlines():
                year_ = line.strip()
                years.append(year_)
            # 会议列表
            file_venues = 'choose_paper/data/venues.txt'
            venues = []
            with open(file_venues,'r',encoding="utf-8") as f:
                for line in f.readlines():
                    venue_ = line.strip()
                    venues.append(venue_)
            # 关键词列表
            key_path = 'choose_paper/data/keywords.txt'
            word_list =[]
            with open(key_path,'r',encoding="utf-8") as f:
                    for line in f.readlines():
                        word = line.strip().split()
                        word_list.append(word)
            # 定义根据年份会议获取数据
            word_dict = {} #某年某个关键词出现的次数统计
            use_data = [] #可视化时传入的data
            yea = str(year) #将输入的年份转为str
            venu = str(venue)
            for i in range(len(years)):
                if yea == years[i].strip() and venu == venues[i].strip():
                    sword = word_list[i]
                    for word in sword:
                        if word in word_dict.keys() and word is not '':
                            word_dict[word]+=1
                        elif word is not '':
                            temp = { }
                            temp[word]=1
                            word_dict.update(temp)
                        else:
                             continue
             # 对word_dict进行处理,筛选词语
            length = len(word_dict)
            if length>60:
                for k,v in word_dict.items():
                    if v>1:
                        tup = (k,v)
                        use_data.append(tup)
            else:
                for k,v in word_dict.items():
                    tup = (k,v)
                    use_data.append(tup)
            ##词云展示:
            wtitle  = str(year)+' '+venue+':关键词词云展示'
            mywordcloud = WordCloud()
            mywordcloud.add('',use_data,shape='triangle')\
               .set_global_opts(title_opts=opts.TitleOpts(
                               title=wtitle))
            mywordcloud.render(path="choose_paper/data/graph/wordCloud.txt")  # 显示图表
            mywordcloud_txt = "{"
            with open('choose_paper/data/graph/wordCloud.txt', 'r', encoding='utf-8') as f:
                line = f.readlines()
                for i in range(16, len(line)-4):
                    mywordcloud_txt += line[i]
              
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值