需要安装pyecharts
pip install pyecharts -U
创建【demo6.py】并输入以下编码:
from pyecharts import options as opts from pyecharts.charts import Page, WordCloud words = [ ("神医", 10000), ("马良", 6181), ("玛丽", 4386), ("终结者", 4055), ("蓝星", 2467), ("慧心", 2244), ("军工", 1868), ("血腥点", 1281) ] def wordcloud_base() -> WordCloud: c = ( WordCloud() .add("", words, word_size_range=[20, 100]) .set_global_opts(title_opts=opts.TitleOpts(title="基本示例")) ) return c wd = wordcloud_base() wd.render("word_demo.html")
点击执行
打开生成的【html】文件
双击打开
效果图如下:
希望能给大家带来帮助。