基于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. php測試程序運行速度和頁面執行速度的代碼2. ASP中常用的22個FSO文件操作函數整理3. 三個不常見的 HTML5 實用新特性簡介4. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報錯問題分析5. ASP調用WebService轉化成JSON數據,附json.min.asp6. SharePoint Server 2019新特性介紹7. React+umi+typeScript創建項目的過程8. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁9. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析10. php網絡安全中命令執行漏洞的產生及本質探究
