def ciyun(txt,k):
words = open(txt, 'r', encoding='UTF-8').read()
wordstr = " ".join(words)
c = Counter(wordstr)
common_c = c.most_common(100)#前一百的关键词
mask = np.array(Image.open('message.jpg'))
wc = WordCloud(
font_path='simhei.ttf', # 设置字体格式
mask=mask,
max_words=200,
max_font_size=100,
stopwords=sw,
scale=4,
).generate(common_c)
# 显示词云图
plt.imshow(wc)
plt.axis("off")
plt.show()
# 保存词云图
wc.to_file(k+'.jpg')
with open('分词结果.txt',encoding='utf-8') as fn:
string_data = fn.read()
ciyun(string_data,'评价词云图')
请问有没有大佬明白这个是什么情况,感觉是文本读取方面出现了问题,但是换了几个用法还是同样的bug