基于python生成英文版詞云圖代碼實(shí)例
使用wordcloud模塊,生成云圖,測(cè)試文本為:
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.
生成云圖代碼:
#導(dǎo)入生成云圖模塊from wordcloud import WordCloudwith open('F:/python入門/數(shù)據(jù)2/fenci_test2.txt' ,encoding='utf-8')as file: #讀取文本 text=file.read() #設(shè)置詞云的字體、背景顏色、寬、高、字?jǐn)?shù) 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()
結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP新手必備的基礎(chǔ)知識(shí)2. asp文件用什么軟件編輯3. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )4. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象5. JAVA 實(shí)現(xiàn)延遲隊(duì)列的方法6. JS中6個(gè)對(duì)象數(shù)組去重的方法7. vue+element開發(fā)一個(gè)谷歌插件的全過程8. Vue axios獲取token臨時(shí)令牌封裝案例9. 通過IEAD+Maven快速搭建SSM項(xiàng)目的過程(Spring + Spring MVC + Mybatis)10. 利用CSS制作3D動(dòng)畫

網(wǎng)公網(wǎng)安備