stopwords = stopwordslist( [line.strip() for line in open('wordCloudstopwords.txt', 'r', encoding='utf-8').readlines()]) wordlist=[] for word in new_cut_text.split(): newword = word.strip() if newword not in stopwords and len(newword)>=2: wordlist.append(word) text = " ".join(wordlist) comment_text=open(r'allForumCommentstrain.txt','r',encoding='gb18030').read() cut_text = " ".join(jieba.cut(comment_text)) new_cut_text = cut_text.replace('\n',"") from wordcloud import WordCloud,ImageColorGenerator import jieba from scipy.misc import imread import matplotlib.pyplot as plt color_mask = imread("dang.png") cloud = WordCloud( font_path="HYQiHei-25J.ttf", background_color='white', mask=color_mask, max_words=2000, max_font_size=150, ) word_cloud = cloud.generate(text) word_cloud.to_file("wc.png") plt.imshow(word_cloud) plt.axis('off') plt.show()