亲宝软件园·资讯

展开

Python pyecharts绘制词云图

悬崖上的金鱼 人气:1

一、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()

加载全部内容

相关教程
猜你喜欢
用户评论