python3 词云
程序员文章站
2022-07-03 12:07:07
...
from wordcloud import WordCloud,ImageColorGenerator
from PIL import Image
import jieba
import numpy as np
import matplotlib.pyplot as plt
text = open(r'D:\python\test\wordcloud\data\jay.txt',encoding='utf-8').read()
cut_text = jieba.cut(text,cut_all='False')
result = ""/"".join(cut_text)
image = Image.open(r'D:\python\test\wordcloud\data\backgroud\image1.png')
graph = np.array(image)
wc = WordCloud(font_path=r'D:\python\test\wordcloud\data\ttf\yahei.ttf',background_color='white',max_font_size=50,mask=graph)
wc.generate(result)
image_color = ImageColorGenerator(graph)
wc.recolor(color_func=image_color)
wc.to_file(r'D:\python\test\wordcloud\output\wordcloud2.png')
plt.figure(""词云图"")
plt.imshow(wc)
plt.axis('off')
plt.show()"
上一篇: uboot环境变量分析
下一篇: 项目总结(一)