欢迎光临散文网 会员登陆 & 注册

Python wordcloud快速生成词云(本教程突出一个快字)

2022-10-09 22:20 作者:珍宝杂货铺  | 我要投稿


效果图1

在Python中绘制词云图需要安装wordcloud。

使用pip命名:pip install wordcloud

软件平台为Pycharm(社区版本),坑爹的没有Python Scientific,需要添加绘图模块matplotlib

效果图1的代码:

 #从wordcloud.py导入WordCloud对象

from wordcloud import WordCloud

 #导入绘制图像的模块

import matplotlib.pyplot as plt


#设置背景色,词组是否重复,重复就写True;词组最多出现200次

wcd=WordCloud(background_color='white',repeat=True ,max_words=200)

#词云的词汇,注意wordcloud无法直接生成正确的中文词云,这里为了快速演示使用英文词汇!

test='hello world python linux html css js'


wcd.generate(test)
wcd.to_image()

#保存生成的图片

wcd.to_file('w-test-01.jpg') 
#显示图像
plt.imshow(wcd)

#关闭绘制图像坐标轴

plt.axis("off") 
plt.show()


Python wordcloud快速生成词云(本教程突出一个快字)的评论 (共 条)

分享到微博请遵守国家法律