其他分享
首页 > 其他分享> > 词云

词云

作者:互联网

# encoding:utf-8

import wordcloud
import jieba
import imageio

mk = imageio.imread("chinamap.jpg")

w = wordcloud.WordCloud(width=1000,
                        height=800,
                        background_color='white',
                        font_path='msyh.ttc',
                        mask=mk,
                        contour_width=0.1,
                        contour_color='steelblue'
                        )



with open('a.txt',encoding='GBK') as f:
    txt = f.read()

txt_list = jieba.lcut(txt)
strings = ''.join(txt_list)

w.generate(strings)

w.to_file('test.png')

 

 

标签:encoding,color,list,词云,import,txt,contour
来源: https://www.cnblogs.com/cforcnb/p/15083733.html