基于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. 如何基于python3和Vue实现AES数据加密2. Python unittest生成测试报告过程解析3. php去掉数组的第一个值的两个函数:array_shift、array_splice4. python matplotlib工具栏源码探析二之添加、删除内置工具项的案例5. CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chrome、Opera6. CSS3实例分享之多重背景的实现(Multiple backgrounds)7. 用PHP读取和编写XML DOM8. 解决VUE项目使用Element-ui 下拉组件的验证失效问题9. uni-app结合PHP实现单用户登陆demo及解析10. 数组在java中的扩容的实例方法

网公网安备