欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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()"