python 词云 wordcloud

试了一下在线的一些词云,很多对文本大小有限制,然后发现Python有wordcloud模块。
示例文本里有136W单词,加载速度也没有很慢
wordcoud的所有参数见:
https://blog.csdn.net/u010309756/article/details/67637930

简单实例

#导入模块
from wordcloud import WordCloud,ImageColorGenerator
import matplotlib.pyplot as plt
from scipy.misc import imread

#加载文本信息
text=open('review.txt','r').read()
#词云样式
bgpic=imread('bg.png')

wordcloud=WordCloud(font_path='C:/Windows/Fonts/Tahoma.ttf',mask=bgpic,background_color='white',scale=2).generate(text)
#注意:font_path设置的字体一定要在C:/Windows/Fonts目录下能找到,否则报错

image_colors=ImageColorGenerator(bgpic)

plt.imshow(wordcloud)
plt.axis('off')
#plt.show()

输出:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44595372/article/details/88845496