【Python小随笔】自定义词云图形
from wordcloud import ImageColorGenerator from matplotlib.image import imread import matplotlib.pyplot as plt # 输出分词组合 ciyun_str = ciyun_word_str(ciyun_raw) back_img = imread("logo.jpg") img_colors = ImageColorGenerator(back_img) word_cloud = WordCloud(font_path="msyh.ttc", background_color="white", max_words=1000, max_font_size=100, width=1920, mask=back_img, height=1080).generate(ciyun_str) # word_cloud.recolor(color_func=img_colors) # 替换默认的字体颜色 plt.figure() # 创建一个图形实例 plt.imshow(word_cloud, interpolation='bilinear') plt.axis("off") # 不显示坐标尺寸 plt.show()
# 输出分词 def ciyun_word_str(text): """ :param text: 文本 :return: A,B,C,D,E,F """ res_str = "" # 文本预处理 remove_words = [u'的', u',', u'和', u'是', u'随着', u'对于', u'对', u'等', u'能', u'都', u'。', u' ', u'、', u'中', u'在', u'了', u'通常', u'如果', u'我们', u'需要',u'很' ,u'也',u'就',u'非常',u'有',u'一',u'!',u'我'] # 自定义去除词库 seg_list_exact = SnowNLP(text).words # 每一个数组评论分词 for word in seg_list_exact: # 循环读出每个分词 if word not in remove_words: # 如果不在去除词库中 res_str = res_str + word + "," return res_str

Python全栈(后端、数据分析、脚本、爬虫、EXE客户端) / 前端(WEB,移动,H5) / Linux / SpringBoot / 机器学习

浙公网安备 33010602011771号