In [1]:
# -*- coding: utf-8 -*-

from wordcloud import WordCloud
 
f = open('wordcloud.txt') 
my_data = f.read() 

text = my_data


# the font from github: https://github.com/adobe-fonts
# font = r'SimHei.ttf'
wc = WordCloud(background_color="white",collocations=False, width=2000, height=1400, margin=2,font_path="/Library/Fonts/Microsoft/SimHei.ttf",).generate(text)

#image_colors = ImageColorGenerator(np.array(Image.open("screenshot.png")))
#plt.imshow(wc.recolor(color_func=image_colors))

plt.imshow(wc)
plt.axis("off")
plt.show()

wc.to_file('show_Chinese.png')  # 把词云保存下来


Out[1]:
<wordcloud.wordcloud.WordCloud at 0x113d9b198>