Python pyecharts繪製詞雲圖

移花宮大公主邀月發表於2021-12-30

 

一、pyecharts繪製詞雲圖WordCloud.add()方法簡介

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

二、繪製詞雲圖對應輪廓按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()

相關文章