基于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 WordCloudwith 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()
结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。
相关文章:
1. Spring自动注入失败的解决方法2. Android 登录页面的实现代码(密码显示隐藏、EditText 图标切换、限制输入长度)3. 解决IDEA springboot"spring-boot-maven-plugin"报红问题4. 用PyCharm轻松安装Python插件5. Javascript怎样使用SessionStorage和LocalStorage6. Java内部类的一些总结7. 解决vue组件销毁之后计时器继续执行的问题8. 用IntelliJ IDEA看Java类图的方法(图文)9. 一个用xslt样式将xml解析为xhtml的类TransformBinder(兼容FF和IE7.0)10. 关于vue的列表图片选中打钩操作

网公网安备