Skip to content

Instantly share code, notes, and snippets.

@powersee
Created January 14, 2019 07:47
Show Gist options
  • Save powersee/e80d7f84a3c695f65c5a36fc91daf279 to your computer and use it in GitHub Desktop.
Save powersee/e80d7f84a3c695f65c5a36fc91daf279 to your computer and use it in GitHub Desktop.
生成中文詞云
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
filename = "cn.txt"
#將文檔命名為 cn.txt
with open(filename) as f:
mytext = f.read()
mytext = " ".join(jieba.cut(mytext))
print (mytext)
wordcloud = WordCloud(font_path="/Users/xxx/Library/Fonts/思源宋体.otf").generate(mytext)
#字體的路勁得自己自定義
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment