Python-政府工作报告词云实例

问题分析

基本思路

  • 步骤1:读取文件、分词整理
  • 步骤2:设置并输出词云
  • 步骤3:观察结果,优化迭代
#CiYun.py
import jieba
import wordcloud
from imageio import imread

mask = imread("logo5.png");

f = open("新时代中国特色社会主义.txt","r",encoding="utf-8");
t = f.read();
f.close();

ls = jieba.lcut(t);
txt = " ".join(ls);
w = wordcloud.WordCloud(font_path="Song.ttf", width=1000, height=700,background_color="white",max_words=15, mask=mask);
w.generate(txt);
w.to_file("grwordcloud.png");

运行结果

 本文仅为学习Python记录,资料来源于中国大学MOOC《Python语言设计》—嵩天

猜你喜欢

转载自blog.csdn.net/cheng6023/article/details/102737143
今日推荐