赞
踩
本教程完整再现了本人使用python将数据可视化为词云的整个过程,包括词云库的安装,分词库的安装与应用、中文文字的显示问题与解决,还有根据图片模板生成指定样式的词云图。
目录
pip install wordcloud
pip install jieba
sudo apt-get install wqy-microhei
pip install numpy
pip install Image
import wordcloud # word cloud lib
import jieba # to show chinese character correctly
import numpy as np # to use mask
from PIL import Image # to use mask
mask = np.array(Image.open("my_mask.png"))
c = wordcloud.WordCloud(width=1000, height=800, font_path="/usr/share/fonts/truetype/wqy-microhei.ttc", mask=mask)
t = "我们都是好孩子,异想天开的孩子"
c.generate(" ".join(jieba.lcut(t)))
c.to_file("my_wordcloud.png")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。