Created
January 14, 2019 07:47
-
-
Save powersee/e80d7f84a3c695f65c5a36fc91daf279 to your computer and use it in GitHub Desktop.
生成中文詞云
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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