Python簡(jiǎn)單實(shí)現(xiàn)詞云圖代碼及步驟解析
一、安裝 wordcloud
pip install wordcloud
二、加載包、設(shè)置路徑
import osfrom wordcloud import WordCloudimport matplotlib.pyplot as pltos.chdir(’E:pyspacetmp’)
三、詞云圖示例
1、默認(rèn)參數(shù)示例
text = ’Keep it simple and stupid.’wc = WordCloud() # 實(shí)例化詞云圖對(duì)象wc.generate(text) # 根據(jù)文本生成詞云圖plt.imshow(wc) # 顯示詞云圖
如果 jupyter 沒有圖形輸出,需要設(shè)置 jupyter 的圖形顯示方式
%matplotlib inline
WordCloud() 詞云圖對(duì)象對(duì)應(yīng)的畫布默認(rèn)長(zhǎng)200像素,寬400像素,背景色為黑色。
2、配置參數(shù)示例
text = ’Keep it simple and stupid.’wc = WordCloud(background_color=’white’, width=500, height=300) # 實(shí)例化詞云圖對(duì)象wc.generate(text) # 根據(jù)文本生成詞云圖plt.imshow(wc) # 顯示詞云圖
3、不顯示坐標(biāo)軸
text = ’Keep it simple and stupid.’wc = WordCloud(background_color=’white’, width=500, height=300) # 實(shí)例化詞云圖對(duì)象wc.generate(text) # 根據(jù)文本生成詞云圖plt.imshow(wc) # 顯示詞云圖plt.axis(’off’) # 不顯示坐標(biāo)軸plt.show()
環(huán)境說(shuō)明:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python爬蟲beautifulsoup解析html方法2. Python 如何將integer轉(zhuǎn)化為羅馬數(shù)(3999以內(nèi))3. python 實(shí)現(xiàn)aes256加密4. 詳解Python模塊化編程與裝飾器5. css進(jìn)階學(xué)習(xí) 選擇符6. Python性能測(cè)試工具Locust安裝及使用7. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式8. 使用Python解析Chrome瀏覽器書簽的示例9. html小技巧之td,div標(biāo)簽里內(nèi)容不換行10. python web框架的總結(jié)
