preface
Word cloud map gives people a very intuitive and special look and feel, which can also be understood as sorting. From the size of the text and its position on the canvas, we can know a certain sorting.Copy the code
code
from pyecharts import WordCloud
# Instantiate an object first
When instantiating an object, you need to set some parameters, such as width, height, etc
In Pyecharts, all classes instantiate objects the same.
wordcloud = WordCloud("Main title"."Subtitle",
title_color=xxx,
title_pos=xxx, # Have options like "center", "left", "right", etc
width=1300,
height=620,
background_color='xxx')
add(name,
attr,
value,
shape="circle",
word_gap=20,
word_size_range=None,
rotate_step=45)
# Parameter description
# name -> STR
# attr -> list, attribute name
# value -> list, the value corresponding to the attribute name
# shape -> STR,
# have 'circle', 'cardioid', 'diamond', 'triangle-forward',
#'triangle', 'pentagon', 'star' optional
# word_gap -> int, word spacing, default is 20.
# word_size_range -> list, font size range of words, default is [12, 60].
# rotate_step -> int;
Note: The rotate_step parameter is valid only if and when the shape parameter is the default 'circle'
attr = [ '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]
All classes in # Pyecharts are initialized with the same input parameters
wordcloud = WordCloud("Global Number of Novel Coronavirus infections"."As of 2021-08-07",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59".)# Word cloud images generally do not require a background color
wordcloud.add("".# This parameter is usually empty because the main and subtitle are added during initialization
attr,
value,
shape='circle'.When the shape is circle, the rotate_step parameter defaults to 45 degrees
word_gap=20,
word_size_range=[20.100])
wordcloud.render()
Copy the code