使用PyEcharts绘制词云图及在jupyter中显示

PyEcharts绘制词云图时,需要注意,版本不同,对应的代码格式不一样,我这个用的是1,7版本的。之前版本的words是分为两部分当做参数传入进去的, 1.7将其合并为一个元组传入。
输出结果默认为html文件,在jupyter中显示结果时,需要添加worldcloud.render_notebook()。

from pyecharts import options as opts
from pyecharts.charts import WordCloud 
name = [
 '嗨', '小子', '风控', '实战', '金融' ,
 '机器学习', '深度学习', '神经网络学习', '反欺诈规则', '强制性规则', '算法',
 '西瓜书', '数据分析', '反欺诈', '数据挖掘', '评分卡',
 'Xgboost', 'pySpark','python', 'pyEcharts']
value = [
 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]

words=[(i,j) for i ,j in zip(name,value)]
worldcloud=(
     WordCloud()
     .add("", words, word_size_range=[20, 100])
     .set_global_opts(title_opts=opts.TitleOpts(title="词云实例"))
     )

worldcloud.render('dd.html')
worldcloud.render_notebook()
worldcloud.render_notebook()  # 这句是用来在jupyter 中显示

输出结果:
使用PyEcharts绘制词云图及在jupyter中显示_第1张图片

你可能感兴趣的:(使用PyEcharts绘制词云图及在jupyter中显示)