【Python小白学习】政府工作报告词云

❗基本思路❗:

       读取文件,分词整理;

       观察并输出词云;

       观察结果,迭代优化。

#GovRptWordCloudv1.py

import jieba
import wordcloud

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

ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(font_path = "msyh.ttx",\
                        width = 1000, height = 700, background_color = "white",\
                        max_words = 15)
w.generate(txt)
w.ro_file("grwordcloud.png")
#GovRptWordCloudv2.py

import jieba
import wordcloud
from scipy.misc import imread

mask = imread("fivestart.png")

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

ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(font_path = "msyh.ttx", mask = mask\
                        width = 1000, height = 700, background_color = "white",\
                        )
w.generate(txt)
w.ro_file("grwordcloud.png")

❗举一反三❗:

       扩展能力:

       设计一款属于自己的特色词云风格(词云形状、文本内容……) 

你可能感兴趣的:(Python)