jieba库配合wordcloud实现中文分词
# -- coding: utf-8 --
# from wordcloud import WordCloud
#
#
#
import wordcloud
import jieba
# c=wordcloud.WordCloud()
# c=c.generate("this is a wordcloud ,python's wordcloud is very useful")
# im=c.to_image() ##转化为图片
# im.show() ##临时显示
#
#
#
c = wordcloud.WordCloud() #加载词云
c.generate("wordcloud by Python") #导入文本数据
c.to_file("pywordcloud.png") #输出图片
w = wordcloud.WordCloud(width=600,height=400,min_font_size=4,max_font_size=20,
background_color="white",max_words=20) ##参数设置 width宽度 默认400; height高度
# 默认200; # min_font_size 最小字号 默认为4;background_color背景颜色;
txt='i love yangsiqi ,life is a sturggle,but i have python, life is a sturggle, but i have python,life is a sturggle,' \
' but i have python,life is a sturggle, but i have python,life is a sturggle, but i have ' \
'python,life is a sturggle, but i have python,' # max_words 显示的最大单词数量,stop_words 不显示的单词
w.generate(txt)
w.to_file('life.png')
txt1="锄禾日当午,汗滴禾下土。谁知盘中餐,粒粒皆辛苦。程序设计语言是计算机能够理解和识别用户操作意图的一种交互体系" \
"他按照特定的规则组织计算机命令"
w1=wordcloud.WordCloud(background_color="green",font_path='msyh.ttc')
w1.generate(" ".join(jieba.lcut(txt1)))
w1.to_file('chinese.png')
im=w1.to_image()
im.show()