Python多种形状的词云
程序员文章站
2022-07-02 22:51:28
生成图片形状的词云关键:wordcloud一、主要需要安装的东西1)jieba2)wordcloud3)imageio二、具体代码实现代码如下(示例):1.代码如下(示例):import jiebaimport wordcloudimport matplotlib.pyplot as pltfrom imageio import imreadmask = imread("D:\\Shuihu\\苹果.jpg")fname = "D:\\Shuihu\\水浒传.txt"....
生成图片形状的词云
关键:wordcloud一、主要需要安装的东西
1)jieba 2)wordcloud 3)imageio二、具体代码实现
代码如下(示例):
1.代码如下(示例):
import jieba
import wordcloud
import matplotlib.pyplot as plt
from imageio import imread
mask = imread("D:\\Shuihu\\苹果.jpg")
fname = "D:\\Shuihu\\水浒传.txt"
f = open(fname,encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(font_path="msyh.ttc",width=1000,\mask=mask,\height=700,background_color="black")
w.generate(txt)
plt.imshow(w)
plt.axis("off")
plt.show()
2.运行结果
总结
革命尚未成功,同志仍需努力本文地址:https://blog.csdn.net/weixin_43909889/article/details/110497425