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 沒(méi)有圖形輸出,需要設(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. 在Android中使用WebSocket實(shí)現(xiàn)消息通信的方法詳解2. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解3. Yii2.0引入CSS,JS文件方法4. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析5. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼6. vue使用webSocket更新實(shí)時(shí)天氣的方法7. 淺談python出錯(cuò)時(shí)traceback的解讀8. android studio 打包自動(dòng)生成版本號(hào)與日期,apk輸入路徑詳解9. Nginx+php配置文件及原理解析10. JavaMail 1.4 發(fā)布
