生成词云

import jieba
import wordcloud
import matplotlib.pyplot as plt

def print_hi(words):
word_list = jieba.lcut(words) # 结巴词库切分词
word_list = [word for word in word_list if len(word.strip())>2]#清洗一个字的词
word_clean=" ".join(word_list)
import imageio
# mask=imageio.imread(r'kobe.jpg')
wc = wordcloud.WordCloud(font_path = "simkai.ttf",#指定字体类型
background_color = "white",#指定背景颜色
max_words = 200, # 词云显示的最大词数
max_font_size = 255 #指定最大字号
) #指定模板
wc = wc.generate(word_clean)##生成词云
plt.imshow(wc)
plt.axis("off")
plt.show()
"""Wordcloud详细参数设置
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/

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容