from os import path
from wordcloud import WordCloud
wc = WordCloud(
background_color="white", #背景顏色
max_words=200, #顯示最大詞數
font_path='./fonts/simhei.ttf'
)
cloud_text = open(path.join('2.txt')).read()
wc.generate(cloud_text)
wc.to_file("pic2.png")
注意:製作中文詞雲時,請添加 font_path='./fonts/simhei.ttf'