python词云图《三国演义》

import jieba
import wordcloud
file = open(“三国演义.txt”, “r”, encoding=“utf-8”)

t = file.read()
file.close()
ls = jieba.lcut(t)

txt = " ".join(ls)
w = wordcloud.WordCloud(
width=1000, height=700,
background_color=“white”,
font_path=“msyh.ttc”
)
w.generate(txt)
w.to_file(“2.png”)

你可能感兴趣的:(笔记)