自己动手做词云

# 安装jieba,wordcloud,matplotlib,pillow
#复制字体并改名
#运行文件输出


import jieba
from wordcloud import WordCloud
txt = '弱小的人,才习惯,嘲讽和否定,而内心,强大的人,从不吝啬赞美和鼓励!我们就是后浪,奔涌吧!后浪,奔涌吧!'


with open(r'./新闻稿.txt','r',encoding='utf-8') as f:
    filecontent=f.read()
    
# print(sss)

words = jieba.lcut(filecontent)     #精确分词
newtxt = ''.join(words)    #空格拼接
wordcloud = WordCloud(font_path = r"./msyh.ttf").generate(newtxt)
wordcloud.to_file('中文词云图.jpg')

你可能感兴趣的:(服务器,linux,python)