温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python如何生成英文版词云图

发布时间:2020-07-27 09:55:18 来源:亿速云 阅读:207 作者:小猪 栏目:开发技术

小编这次要给大家分享的是python如何生成英文版词云图,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

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

Betty Botter bought some butter but she said the butter's 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()

结果:

python如何生成英文版词云图

看完这篇关于python如何生成英文版词云图的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI