From d13c4b617c70ae1345f151a748c700efa5046be5 Mon Sep 17 00:00:00 2001 From: hnu202309010201 <110050040@qq.com> Date: Mon, 10 Jun 2024 18:52:43 +0800 Subject: [PATCH] ADD file via upload --- 中文.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 中文.py diff --git a/中文.py b/中文.py new file mode 100644 index 0000000..8a8057f --- /dev/null +++ b/中文.py @@ -0,0 +1,29 @@ +# -*- 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() \ No newline at end of file