生成詞云

import jieba
import wordcloud
import matplotlib.pyplot as plt

def print_hi(words):
word_list = jieba.lcut(words) # 結(jié)巴詞庫(kù)切分詞
word_list = [word for word in word_list if len(word.strip())>2]#清洗一個(gè)字的詞
word_clean=" ".join(word_list)
import imageio
# mask=imageio.imread(r'kobe.jpg')
wc = wordcloud.WordCloud(font_path = "simkai.ttf",#指定字體類(lèi)型
background_color = "white",#指定背景顏色
max_words = 200, # 詞云顯示的最大詞數(shù)
max_font_size = 255 #指定最大字號(hào)
) #指定模板
wc = wc.generate(word_clean)##生成詞云
plt.imshow(wc)
plt.axis("off")
plt.show()
"""Wordcloud詳細(xì)參數(shù)設(shè)置
def init(self, font_path=None, width=400, height=200, margin=2,
ranks_only=None, prefer_horizontal=.9, mask=None, scale=1,
color_func=None, max_words=200, min_font_size=4,
stopwords=None, random_state=None, background_color='black',
max_font_size=None, font_step=1, mode="RGB",
relative_scaling='auto', regexp=None, collocations=True,
colormap=None, normalize_plurals=True, contour_width=0,
contour_color='black', repeat=False,
include_numbers=False, min_word_length=0):
"""

Press the green button in the gutter to run the script.

if name == 'main':
word ="""
此處要分析的文本
"""
print_hi(word)

See PyCharm help at https://www.jetbrains.com/help/pycharm/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容