Python用来做词云图片

#在cmd安装三个库 

pip install jieba

pip install  matplotlib

pip  install  wordcloud

#在PyCharm安装库,按File-->Settings-->Project:-->Project Interpreter-->点击+后会弹出页面

查找wordcloud库-->然后点击wordcloudku-->再点Install   Package -->弹出installed successfully才安装成功

 

 

#在安装三个库完成后,实现如下代码: 

import jieba

from wordcloud import WordCloud


with open("标准输出与输入.txt") as fp:
    txt = fp.read()  # 读取文本

words = jieba.lcut(txt)  # 精确分词

nextword = ' '.join(words)    #空格连接字符

wordshow = WordCloud(background_color='white',
                     width=800,
                     height=800,
                     max_words=800,
                     max_font_size=100,
                     font_path="msyh.ttc",    #用微软雅黑作为字体显示效果

                     ).generate(nextword)

wordshow.to_file('tes4.png')  #转换成图片

#图片效果 

 

猜你喜欢

转载自blog.csdn.net/qq_41709494/article/details/89213176