Python词云

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()

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值