Python模塊:wordcloud庫的使用

Python模塊:wordcloud庫的使用

wordcloud庫基本介紹

wordcloud是優秀的詞雲展示第三方庫
詞雲以詞語爲基本單位,更加直觀和藝術的展示文本
wordcloud庫安裝
(cmd命令行) pip install wordcloud
這裏寫圖片描述

wordcloud庫的使用說明

wordcloud庫把詞雲當作一個WordCloud對象
wordcloud.WordCloud()代表一個文本對應的詞雲
可以根據文本中詞語出現的頻率等參數繪製詞雲
繪製詞雲的形狀、尺寸和顏色都可以設定
w=wordcloud.WordCloud()
以WordCloud對象爲基礎
配置參數、加載文本、輸出文件
方法:w.generate(txt)、w.to_file(filename)
這裏寫圖片描述
繪製步驟
步驟1:配置對象參數
:步驟2:加載詞雲文本
:步驟3:輸出詞雲文件
import wordcloud
c = wordcloud.WordCloud()
c.generate("wordcloud by Python")
c.to_file("pywordcloud.png")

這裏寫圖片描述
這裏寫圖片描述

配置對象參數
w = wordcloud.WordCloud(<參數>)、min_font_size、max_font_size、font_step、font_path、max_words、stop_words、mask、background_color
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
import wordcloud
txt = "life is short,you need python"
w = wordcloud.WordCloud(background_color = "white")
w.generate(txt)
w.to_file("pywcloud.png")

這裏寫圖片描述
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章