基于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è)置詞云的字體、背景顏色、寬、高、字數(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é)習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP實現(xiàn)加法驗證碼2. ASP刪除img標簽的style屬性只保留src的正則函數(shù)3. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁4. 怎樣才能用js生成xmldom對象,并且在firefox中也實現(xiàn)xml數(shù)據(jù)島?5. 小技巧處理div內(nèi)容溢出6. JSP實現(xiàn)文件上傳功能7. JavaWeb Servlet中url-pattern的使用8. asp知識整理筆記4(問答模式)9. JSP+Servlet實現(xiàn)文件上傳到服務(wù)器功能10. jsp+servlet實現(xiàn)猜數(shù)字游戲
