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 WordCloud
with 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()

結果:

 

  ps:中文的測試沒成功,先來個英文版。

 原文鏈接:https://blog.csdn.net/weixin_36279318/article/details/79278403


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM