界面展示
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]