python简单词云应用
词云
# 必须要有这些库
# 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')