代码如下:
from os import path
from wordcloud import WordCloud
import matplotlib
matplotlib.use('TkAgg')
# 获取目录地址,读取文本
d = path.dirname(__file__)
text = open(path.join(d, 'haha.txt')).read()
# 生成一个词云图像
wordcloud = WordCloud().generate(text)
# pil方式展示生成的词云图像
image = wordcloud.to_image()
image.show()
from os import path
from PIL import Image
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
from wordcloud import WordCloud, STOPWORDS
d = path.dirname(__file__)
# 读取整个文本.
text = open(path.join(d, 'haha.txt')).read()
#读取图片
alice_mask = np.array(Image.open(path.join(d, "heart.png")))
#添加停用词
stopwords = se
Python生成词云图
最新推荐文章于 2024-04-22 14:24:30 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)