Python簡單實現(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() # 實例化詞云圖對象wc.generate(text) # 根據(jù)文本生成詞云圖plt.imshow(wc) # 顯示詞云圖
如果 jupyter 沒有圖形輸出,需要設(shè)置 jupyter 的圖形顯示方式
%matplotlib inline
WordCloud() 詞云圖對象對應(yīng)的畫布默認(rèn)長200像素,寬400像素,背景色為黑色。
2、配置參數(shù)示例
text = ’Keep it simple and stupid.’wc = WordCloud(background_color=’white’, width=500, height=300) # 實例化詞云圖對象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) # 實例化詞云圖對象wc.generate(text) # 根據(jù)文本生成詞云圖plt.imshow(wc) # 顯示詞云圖plt.axis(’off’) # 不顯示坐標(biāo)軸plt.show()
環(huán)境說明:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 完美解決vue 中多個echarts圖表自適應(yīng)的問題2. SpringBoot+TestNG單元測試的實現(xiàn)3. vue實現(xiàn)web在線聊天功能4. idea配置jdk的操作方法5. Docker容器如何更新打包并上傳到阿里云6. Springboot 全局日期格式化處理的實現(xiàn)7. python 浮點數(shù)四舍五入需要注意的地方8. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法9. Java GZip 基于內(nèi)存實現(xiàn)壓縮和解壓的方法10. JAMon(Java Application Monitor)備忘記
