1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import jieba import wordcloud
with open("read.txt",encoding="utf-8") as f: paragragh = f.read()
ls = jieba.lcut(paragragh)
text = ' '.join(ls)
''' 可以从网上找停用词表,也可以自己定义 也可以在默认词表追加,方法如下: from wordcloud import STOPWORDS stopwords = STOPWORDS stopwords.add('xxx') # 集合, 需要使用add()或update()方法 ''' stopwords = set() content = [] stopwords.update(content)
wc = wordcloud.WordCloud( font_path='SimHei.ttf', width = 1000, height = 1000, background_color='white', max_words=100, stopwords=stopwords )
wc.generate(text)
wc.to_file("write.png")
|