parent
60a82a7cfc
commit
9131840145
@ -1,19 +0,0 @@
|
||||
#生成词云
|
||||
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")
|
Loading…
Reference in new issue