词云

# 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')

 

 

posted @ 2021-07-31 11:30  cforcnb  阅读(66)  评论(0)    收藏  举报