From 3430fc72f1e82e804601e205e47b363e8a54945a Mon Sep 17 00:00:00 2001 From: pe79kpq4w <310771302@qq.com> Date: Wed, 30 Mar 2022 21:06:13 +0800 Subject: [PATCH] Create word cloud --- CreateCloud.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 CreateCloud.py diff --git a/CreateCloud.py b/CreateCloud.py new file mode 100644 index 0000000..a7828c8 --- /dev/null +++ b/CreateCloud.py @@ -0,0 +1,19 @@ +#生成词云 +import wordcloud +import numpy as np +from PIL import Image + +#生成词云的背景的图片数组 +bgImage = ['CROWN.png', 'aSTAR.PNG', 'block.PNG'] +def createcloud(str, filename, bgi): + print("----------------------生成词云中---------------------------") + image = Image.open(bgImage[bgi]) # 打开背景图 + graph = np.array(image) # 读取背景图 + w = wordcloud.WordCloud(font_path="C:\Windows\Fonts\msyhbd.ttc", background_color="black", mask=graph) + #str是已经处理好词频字符串 + w.generate(str) + # 生成图片的名字,以文件名命名 + png = "res" + filename.split('.')[0] + png += '.png' + w.to_file(png) + print("生成词云完成,请到文件夹中查看\n") \ No newline at end of file