利用python生成词云(适合初学者)
程序员文章站
2022-03-12 12:42:19
测试资源链接:https://python123.io/resources/pye/%E6%96%B0%E6%97%B6%E4%BB%A3%E4%B8%AD%E5%9B%BD%E7%89%B9%E8%89%B2%E7%A4%BE%E4%BC%9A%E4%B8%BB%E4%B9%89.txtimport jiebaimport wordcloudf = open("新时代*.txt", "r", encoding="utf-8") t = f.read()f.close()ls = ji...
词云:
关键词云是对海量文字内容中出现频率较高的“关键词”的视觉突出,即出现越多的“关键词”字体越大。比如说可以根据上千条新闻进行词频统计,得到很多个“关键词”,再按照关键词出现的次数进行排序,越显著的“关键词”,在所有新闻内容中出现的频率越高。
import jieba
import wordcloud
f = open("新时代*.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud( \
width = 1000, height = 700,\
background_color = "white",
font_path = "msyh.ttc"
)
w.generate(txt)
w.to_file("grwordcloud.png")
效果图:
本文地址:https://blog.csdn.net/qq_45624989/article/details/107394726