参考:https://mp.weixin.qq.com/s/B23uDxzLUa_45uDh2R9Vlw
安装:
pip install stylecloud 即可安装
直接调用 txt 文本生成词云:
from stylecloud import gen_stylecloud
gen_stylecloud(file_path='Trump.txt',output_name'1.png')
词云形状:
蒙版链接-https://fa5.dashgame.com/#/%E5%9B%BE%E6%A0%87
可以定期更新,见参考链接
调用狗的蒙版:
stylecloud.gen_stylecloud(text=' '.join(text1), collocations=False,
font_path=r'C:\Windows\Fonts\msyh.ttc',
icon_name='fas fa-dog',
size=400,output_name='词云.png')
icon_name 参数,有 fas,far,fab,三种前缀,要哪一种图就用哪一种,比如要调用狗,还需 fa 前缀,其他也一样
配色:
from stylecloud import gen_stylecloud
word = jieba.lcut(title_word)
gen_stylecloud(text=' '.join(word), collocations=False,
palette='tableau.BlueRed_6',
font_path=r'C:\Windows\Fonts\msyh.ttc',
icon_name='fas fa-building',
size=400,output_name='../标题词云.png')
palett 参数,取值-https://jiffyclub.github.io/palettable/#finding-palettes,参考链接
jupyter notebook 中显示
不需要分词的
from IPython.display import Image
import stylecloud
stylecloud.gen_stylecloud(
text=name,
collocations=False,
font_path=r'C:\Windows\Fonts\msyh.ttc',
icon_name='fas fa-tv',
size=768,
output_name='节目名称词云图.png'
)
Image(filename='节目名称词云图.png')