#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语言设计》—嵩天