Skip to content

Instantly share code, notes, and snippets.

@zjuyk
Created August 17, 2021 21:33
Show Gist options
  • Save zjuyk/b0c565394f3b9315d4e6bf6e63580e4a to your computer and use it in GitHub Desktop.
Save zjuyk/b0c565394f3b9315d4e6bf6e63580e4a to your computer and use it in GitHub Desktop.
从 txt 生成词云
import jieba
from wordcloud import WordCloud
file = open("input.txt", encoding='utf-8')
word_stream = file.read()
word_list = jieba.lcut(word_stream)
word_string = " ".join(word_list)
w = WordCloud('NotoSansCJK-Regular.ttc', width=1920, height=1080)
w.generate(word_string)
image = w.to_image()
image.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment