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()"
python3 词云
最新推荐文章于 2021-11-29 00:39:43 发布