新时代中国特色社会主义报告的分析:
import jieba
import wordcloud
f=open("新时代中国特色社会主义.txt","r",encoding="utf-8")
tad()
f.close()
ls=jieba.lcut(t)
txt=" ".join(ls)
w=wordcloud.WordCloud(font_path=",width=1000,height=700,background_color="white")
w.generate(txt)
w.to_file("ground.png")
运行结果:生成的文件如下
设置最大的文字输出数量为15:增加新的参数 max_words=15
import jieba
import wordcloud
f=open("关于实施乡村振兴战略的意见.txt","r",encoding="utf-8")
tad()
f.close()
ls=jieba.lcut(t)
txt=" ".join(ls)
w=wordcloud.WordCloud(font_path=",width=1000,height=700,background_color="white",max_words=15)
w.generate(txt)
w.to_file("ground.png")
显示结果:
生成更有型的词云:
import jieba
import wordcloud
import imageio
#from scipy.misc import imread
mask=imageio.imread("fivestar.png")
f=open("新时代中国特色社会主义.txt","r",encoding="utf-8")
tad()
f.close()
ls=jieba.lcut(t)
txt=" ".join(ls)
w=wordcloud.WordCloud(font_path=",mask=mask,width=1000,height=700,background_color="white",)
w.generate(txt)
w.to_file("grwordcloud.png")
import jieba
import wordcloud
import imageio
#from scipy.misc import imread
mask=imageio.imread("chinamap.png")
f=open("新时代中国特色社会主义.txt","r",encoding="utf-8")
tad()
f.close()
ls=jieba.lcut(t)
txt=" ".join(ls)
w=wordcloud.WordCloud(font_path=",mask=mask,width=1000,height=700,background_color="white",)
w.generate(txt)
w.to_file("grwordcloud.png")
本文发布于:2024-02-02 10:27:47,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170684086643195.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |