基于python生成英文版詞云圖代碼實(shí)例
使用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. 解析原生JS getComputedStyle2. CSS3中Transition屬性詳解以及示例分享3. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫特效4. 利用CSS3新特性創(chuàng)建透明邊框三角5. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案6. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)7. IE6/IE7/IE8/IE9中tbody的innerHTML不能賦值的完美解決方案8. XML入門的常見問題(二)9. XML入門的常見問題(一)10. 阿里前端開發(fā)中的規(guī)范要求
