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

相關文章
相關標籤/搜索