python,利用jieba, wordcloud库生成中文词云实例

import wordcloud
import jieba
font = r'C:\Windows\Fonts\simfang.ttf'
w = wordcloud.WordCloud(height = 700, width = 1000, font_path=font, \
                        stopwords=['et','al', 'Crampin', 'and','the', 'Liu'], max_words=30)

with open('NSFC.txt', 'r') as f:
    txt = f.read()
txt = ' '.join(jieba.lcut(txt))
print(txt)
w.generate(txt)
w.to_file('world.png')

  准备文件:需要在当前程序运行目录准备一个中文文本文件NSFC.txt。

程序运行后,完成对NSFC.txt文件中的中文统计,并输出图形文件展示词云。

图片效果如下:

猜你喜欢

转载自www.cnblogs.com/iceberg710815/p/12613432.html