From b68c740f51e704ac4484668a84a788f8ca435321 Mon Sep 17 00:00:00 2001 From: Qyalifpq9 Date: Mon, 8 Nov 2021 23:15:43 +0800 Subject: [PATCH] ADD file via upload --- picture.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 picture.py diff --git a/picture.py b/picture.py new file mode 100644 index 0000000..f90bbb0 --- /dev/null +++ b/picture.py @@ -0,0 +1,36 @@ +# -*- codeing utf-8 -*- +# @Time :2021/11/613:48 +# @Author :1900301218 +# @File :picture.py +# @Software :PyCharm +from wordcloud import WordCloud +import cv2 +import jieba +import matplotlib.pyplot as plt + +with open('pythonworkinfo.txt', 'r') as f: + text = f.read() + +cut_text = " ".join(jieba.cut(text)) + +color_mask = cv2.imread('hh.jpg') + +cloud = WordCloud( + # 设置字体,不指定就会出现乱码 + font_path=" C:\\Windows\\Fonts\\simsun.ttc", + # font_path=path.join(d,'simsun.ttc'), + # 设置背景色 + background_color='white', + # 词云形状 + mask=color_mask, + # 允许最大词汇 + max_words=2000, + # 最大号字体 + max_font_size=40 +) + +wCloud = cloud.generate(cut_text) +wCloud.to_file('cloud.jpg') +plt.imshow(wCloud, interpolation='bilinear') +plt.axis('off') +plt.show() \ No newline at end of file