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)境說明:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 如何利用python操作注冊(cè)表2. vue3+ts+elementPLus實(shí)現(xiàn)v-preview指令3. Xml簡(jiǎn)介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理4. jsp文件下載功能實(shí)現(xiàn)代碼5. 詳解瀏覽器的緩存機(jī)制6. ASP動(dòng)態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享7. phpstudy apache開啟ssi使用詳解8. 如何在jsp界面中插入圖片9. xml中的空格之完全解說10. JSP之表單提交get和post的區(qū)別詳解及實(shí)例
