新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python詞云安裝什么庫
python詞云需要安裝wordcloud庫。

安裝方法:
在cmd使用pip install wordcloud命令即可安裝。
wordcloud庫把詞云當(dāng)作一個WordCloud對象:wordcloud.WordCloud()代表一個文本對應(yīng)的詞云。
可以根據(jù)文本中詞語出現(xiàn)的頻率等參數(shù)繪制詞云。
示例:
from wordcloud import WordCloud
f = open(u'D:\\PythonStudio\\WORK\\Demo1\\test.txt','r').read()
wordcloud = WordCloud(background_color="black",width=1000, height=860, margin=2).generate(f)
#width,height,margin可以設(shè)置圖片屬性
# generate 可以對全部文本進(jìn)行自動分詞,但是他對中文支持不好,對中文的分詞處理請看我的下一篇文章
#wordcloud =WordCloud(font_path = r'D:\Fonts\simkai.ttf').generate(f)
# 你可以通過font_path參數(shù)來設(shè)置字體集
#background_color參數(shù)為設(shè)置背景顏色,默認(rèn)顏色為黑色
import matplotlib.pyplot as plt
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
wordcloud.to_file('test.png')
新聞標(biāo)題:創(chuàng)新互聯(lián)Python教程:python詞云安裝什么庫
瀏覽地址:http://fisionsoft.com.cn/article/cdscigc.html


咨詢
建站咨詢
