使用停用词制作词云
使用《红楼梦》停用词.txt 、《红楼梦》完整版.txt 以及下载的 simhei.ttf
import jieba
import codecs
from wordcloud import WordCloud
import matplotlib.pyplot as plt #重命名
file=codecs.open('《红楼梦》完整版.txt','r',encoding='utf-8')
text=file.read()
wordlist=jieba.cut(text)
word_str=''
for word in wordlist:
if(len(word)>1):
word_str=word_str+" "+word #字符串的拼接
print(word_str)
wc=WordCloud(background_color='black',
max_words=2000,
font_path='c:/simhei.ttf',
max_font_size=150,
random_state=50,
width=1600,
height=900,
margin=2
)
my_word_cloud=wc.generate(word_str)
plt.imshow(my_word_cloud)
plt.axis('off')
plt.show()