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)