基于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.
生成云圖代碼:
#導(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é)果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python 爬取豆瓣網(wǎng)頁的示例2. asp知識整理筆記4(問答模式)3. Java雙向鏈表按照順序添加節(jié)點的方法實例4. AJAX的跨域問題解決方案5. phpstudy apache開啟ssi使用詳解6. Python實現(xiàn)播放和錄制聲音的功能7. Android實現(xiàn)簡單用戶注冊案例8. 深入理解Android熱修復(fù)技術(shù)原理之代碼熱修復(fù)技術(shù)9. Javascript中Math.max和Math.max.apply的區(qū)別和用法詳解10. ASP 連接Access數(shù)據(jù)庫的登陸系統(tǒng)
