You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
754 B

3 years ago
#生成词云
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")