首页 > 编程语言 > 详细

python生成词云图(英文版)

时间:2020-05-10 23:24:51      阅读:115      评论:0      收藏:0      [点我收藏+]

  使用wordcloud模块,生成云图,测试文本为: 

Betty Botter bought some butter but she said the butters bitter. If I put it in my batter it will make my batter bitter. So, she bought some better butter, better than the bitter butter and she put it in her batter and her batter was not bitter. So twas good that Betty Botter bought some better butter.

生成云图代码:

#导入生成云图模块
from wordcloud import WordCloud
with open("F:/python入门/数据2/fenci_test2.txt" ,encoding="utf-8")as file:
    #读取文本
    text=file.read()
    #设置词云的字体、背景颜色、宽、高、字数
    wordcloud=WordCloud(font_path="C:/Windows/Fonts/Tahoma.ttf",
    background_color="black",width=600,
    height=300,max_words=50).generate(text)
    #生成图片
    image=wordcloud.to_image()
    #显示图片
    image.show()

结果:

技术分享图片

 

  ps:中文的测试没成功,先来个英文版。

技术分享图片

 原文链接:https://blog.csdn.net/weixin_36279318/article/details/79278403

python生成词云图(英文版)

原文:https://www.cnblogs.com/xiao02fang/p/12865699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!