白云岛资源网 Design By www.pvray.com
wordcloud是优秀的词云展示第三方库
一、基本使用
import jieba import wordcloud txt = open("1.txt", "r", encoding='utf-8').read() words = jieba.lcut(txt) txt_1 = " ".join(words) # print(txt1) w = wordcloud.WordCloud(font_path="msyh.ttc", width=1000, height=700, background_color="white", ) w.generate(txt_1) w.to_file("ciyun.png")
二、按图片形状生成
import jieba from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator import numpy as np from PIL import Image txt = open("C:/Users/96356/Desktop/1.txt", "r", encoding='utf-8').read() words = jieba.lcut(txt) txt_1 = " ".join(words) photo = np.array(Image.open('C:/Users/96356/Desktop/2.png')) # from scipy.misc import imread # china=imread('C:/Users/96356/Desktop/2.png') #scipy.misc方式都可以读取图片 w = WordCloud(font_path="msyh.ttc", mask=photo, background_color="white", ) w.generate(txt_1) w.to_file("ciyun.png")
三、WordCloud参数详解
from wordcloud import WordCloud
其他部分函数
更多关于python词云库wordcloud的使用方法请查看下面的相关文章
白云岛资源网 Design By www.pvray.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
白云岛资源网 Design By www.pvray.com
暂无评论...