python

关注公众号 jb51net

关闭
首页 > 脚本专栏 > python > Python pyecharts绘制词云图

Python pyecharts绘制词云图代码

作者:悬崖上的金鱼

这篇文章主要介绍了Python pyecharts绘制词云图代码,

一、pyecharts绘制词云图WordCloud.add()方法简介

WordCloud.add()方法简介:

二、绘制词云图对应轮廓按diamond显示

name = [
    'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
    'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
    'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
    'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
value = [
    10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
    965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
wordcloud = WordCloud(width=1300, height=620)
wordcloud.add("我爱新中国", name, value, word_size_range=[30, 60])
page.add(wordcloud)

wordcloud2 = WordCloud(width=1300, height=620)
wordcloud2.add("", name, value, word_size_range=[30, 100],
              shape='diamond',word_gap=60)

三、对应完整代码如下所示

from pyecharts import Page
from pyecharts import WordCloud
page = Page()
#词云(词云图)
'''
WordCloud.add()方法简介
     add(name,attr,value,
     shape="circle",
     word_gap=20,
     word_size_range=None,
     rotate_step=45)
     name str 图例名称
     attr list 属性名称
     value list  属性所对应的值
     shape 词云图轮廓 对应属性可选'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
     word_gap int 字符间隔默认为20
     word_size_range 字符范围默认为[12,60]
     rotate_step int 旋转角度默认为45
'''
name = [
    'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
    'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
    'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
    'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
value = [
    10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
    965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
wordcloud = WordCloud(width=1300, height=620)
wordcloud.add("我爱新中国", name, value, word_size_range=[30, 60])
page.add(wordcloud)

wordcloud2 = WordCloud(width=1300, height=620)
wordcloud2.add("", name, value, word_size_range=[30, 100],
              shape='diamond',word_gap=60)
page.add(wordcloud2)
page.render()

到此这篇关于Python pyecharts绘制词云图代码的文章就介绍到这了,更多相关Python pyecharts绘制词云图内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文