# -*- coding: utf-8 -*- """ Created on Mon Jun 10 18:48:47 2024 @author: Peter """ from wordcloud import WordCloud import matplotlib.pyplot as plt from wordcloud import STOPWORDS from matplotlib.font_manager import FontProperties import jieba font_path = "C:/Windows/Fonts/SimHei.ttf" font_prop = FontProperties(fname=font_path, size=14) with open(r'C:\jieba-python\中文\yyy.txt', encoding='gb18030') as file: txt = file.read() words = " ".join(jieba.cut(txt, cut_all=False)) wordcloud = WordCloud( font_path=font_path, width=800, height=400, background_color='white', stopwords=STOPWORDS ).generate(words) plt.figure(figsize=(15, 10)) plt.imshow(wordcloud, interpolation='bilinear') plt.axis('off') plt.savefig(r'C:\jieba-python\中文\yyy.png', dpi=300, bbox_inches='tight') plt.close()