python3形成《三国演义》词云

利用jieba库和imaeio库生成《三国演义》词云

#CloudSanGuo.py
import jieba
import wordcloud
from imageio import imread

mask = imread("fan.png")

f = open("threekingdoms.txt", "r", encoding = "utf-8")
t = f.read()
f.close()

ls = jieba.lcut(t)
txt = " ".join(ls)

w = wordcloud.WordCloud( font_path= "msyh.ttc", mask = mask, width = 1000, height = 700, background_color = "white")

w.generate(txt)
w.to_file("threekingdoms.png")

结果

全部评论

相关推荐

10-20 11:11
辽宁大学 营销
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务