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


浙公网安备 33010602011771号