基于python生成英文版詞云圖代碼實(shí)例
使用wordcloud模塊,生成云圖,測(cè)試文本為:
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 WordCloud with open("F:/python入門(mén)/數(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é)果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解OpenCV中簡(jiǎn)單的鼠標(biāo)事件處理
談及鼠標(biāo)事件,就是在觸發(fā)鼠標(biāo)按鈕后程序所做出相應(yīng)的反應(yīng),但是不影響程序的整個(gè)線程。本文將主要介紹OpenCV中的簡(jiǎn)單鼠標(biāo)事件處理,感興趣的可以學(xué)習(xí)一下2022-01-01Python學(xué)習(xí)之魔法函數(shù)(filter,map,reduce)詳解
這篇文章我們將來(lái)學(xué)習(xí)一下,Python中的三個(gè)高級(jí)函數(shù):filter()、map()、reduce(),這三個(gè)函數(shù)也被稱為魔法函數(shù),感興趣的小伙伴可以了解一下2022-04-04Python利用pandas對(duì)數(shù)據(jù)進(jìn)行特定排序
本文主要介紹了Python利用pandas對(duì)數(shù)據(jù)進(jìn)行特定排序,主要使用?pandas.DataFrame.sort_values?方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-03-03詳解多線程Django程序耗盡數(shù)據(jù)庫(kù)連接的問(wèn)題
這篇文章主要介紹了多線程Django程序耗盡數(shù)據(jù)庫(kù)連接的問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10