jieba
import jiebaimport wordcloud
import pandas as pd
import matplotlib as plt
fname = input()
f = open(fname, 'r')
text = f.read()
f.close()
cut_text = jieba.lcut(text)
f = open()
stop_words = "".join(f.read())
stop_words.join('\n\t')
f.close()
stop_words_list = stop_words.split('\n')
stop_words_list.append('\n')
filted_text_list = []
for s in cut_text:
if s not in stop_words_list:
filted_text_list.append(s)
words_dic = {}
for s in filted_text_list:
words_dic[s] = words_dic.get(s, 0) + 1#统计词频
words_list = list(words_dic.items())
words_list.sort(key=lambda x: x[1],reverse=True)
words_dic = dict(words_list)
cloud_words_list = list(words_dic.keys())
cloud_words = " ".join(cloud_words_list[:20])
wc=wordcloud.WordCloud(font_path="simhei.ttf", width=300, height=250, background_color="#ffffff", max_font_size=80, random_state=50, prefer_horizontal=0.9)
wc_im=wc.generate_from_text(cloud_words)
wc_im.to_image().save
plt.pyplot.imshow(wc, interpolation="bilinear")
浙公网安备 33010602011771号