Created
August 17, 2021 21:33
-
-
Save zjuyk/b0c565394f3b9315d4e6bf6e63580e4a to your computer and use it in GitHub Desktop.
从 txt 生成词云
This file contains 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
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