生成图片形状的词云
关键: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()