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')

posted @ 2019-07-19 15:08  豆瓣酱瓣豆  阅读(217)  评论(0编辑  收藏  举报