栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python词云

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/348668.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号