词云
# 必须要有这些库
# pip install matplotlib
# pip install wordcloud
# pip install scipy
# pip install pillow
# pip install imageio
import wordcloud
from imageio import imread
mask = imread(r"F:\教师课程\day 06\test7.png")
f = open(r'threekingdoms.txt', 'r', encoding='utf8')
data = f.read()
w = wordcloud.WordCloud(font_path=r'C:\Windows\Fonts\simkai.ttf', mask=mask, width=1000, height=700,
background_color="white")
w.generate(data)
w.to_file('outfile.png')
作 者:豆瓣酱瓣豆
出 处:https://www.cnblogs.com/chenziqing/
查看其它博文请点击:https://www.cnblogs.com/chenziqing/
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
微信:
原文地址:https://www.cnblogs.com/chenziqing/p/11213369.html
时间: 2024-10-06 04:18:19