SoFunction
Updated on 2024-11-12

A complete list of uses for the python pyecharts library

What are pyecharts?

pyecharts is a class library for generating Echarts charts.

echarts is a Baidu open source data visualization JS library , mainly used for data visualization . pyecharts is a class library for generating Echarts charts . In fact, it is Echarts and Python interface.

Using pyecharts can generate standalone web pages, can also be used in flask , Django integration .

Charts included in pyecharts#
Bar (column/bar chart)
Bar3D (3D Bar Chart)
Boxplot
EffectScatter (scatterplot with ripple effect animation)
Funnel
Gauge
Geo (geographic coordinate system)
Graph
HeatMap
Kline (K-line chart)
Line (line/area map)
Line3D (3D Line Chart)
Liquid (water balloon chart)
Map
Parallel (parallel coordinate system)
Pie (pie chart)
Polar (polar coordinate system)
Radar
Sankey (Sangitu)
Scatter
Scatter3D (3D Scatterplot)
ThemeRiver
WordCloud

User-defined

Grid class: display multiple charts in parallel
Overlap class: combining different types of charts overlaid on the same chart
Page class: display multiple images in the same web page in sequence
Timeline class: provide timeline rotation of multiple images

pyecharts installation

 pip install pyecharts

Here is an introduction to the use of python pyecharts library together!

The libraries you download now are all versions, and the way you use them is very different from before

(of cargo etc) load

from  import Line, Bar, Funnel
from  import Faker
import  as opts
from  import JsCode

Drawing of line graphs

Simplest version

line1 = (
 Line()
 .add_xaxis(['2015', '2016', '2017', '2018', '2019'])
 .add_yaxis('% entering party and government organizations and institutions', [30.23, 15.06, 17.6, 16.56, 18.51])
)

line1.render_notebook()

在这里插入图片描述

advanced version

Multiple lines, image sizes, setting titles, legends and their positions, plotting of missing data, and coloring of legends to distinguish between them

# /seakingx/article/details/105531515 Plotting percentages
# /article/2819552517/ Legend add color, color parameter, non-subparameter of linestyle_opts
line1 = (
 Line(init_opts=(width="600px", height="400px"))
 .add_xaxis(['2015', '2016', '2017', '2018', '2019'])
 .add_yaxis('% entering party and government organizations and institutions', [30.23, 15.06, 17.6, 16.56, 18.51], 
    label_opts=(formatter=JsCode("function (params) {return [1] + '%'}"))
    )
 .add_yaxis('Proportion of state-owned enterprises, private enterprises and three-funded enterprises under contract %', [69.78, 84.78, None, 82.67, 81.33], 
    label_opts=(formatter=JsCode("function (params) {return [1] + '%'}")),
    #linestyle_opts=(color='yellow', width=2)
    #linestyle_opts=(width=2),
    color='blue'
    )
 .set_global_opts(title_opts=(title='Career destinations and proportion of undergraduates at Nankai University',
            pos_right='50%'
            ),
      legend_opts=(pos_right='10%',
            pos_top='10%',
            orient='vertical')
     )
 #.render('Nankai Undergraduate.html')
)

line1.render_notebook()

在这里插入图片描述

Error reporting and unresponsiveness of render() with render_notebook:

If line1 has render code, you can't add render_notebook to the code, or else you get an error: AttributeError: 'str' object has no attribute 'render_notebook'.

Combination of bar charts and line graphs

Simplest form

x = ()
scatter1 = (
 Bar()
 .add_xaxis(x)
 .add_yaxis("Merchant A", (), yaxis_index=0) 
 # This command must be added when setting the secondary axes. This command does not determine the primary and secondary axes.
 .extend_axis(yaxis=(type_="value", name="Merchant A", position="left")) 
 .set_global_opts(yaxis_opts=(type_="value", name="Merchant B", position="right")) 
)

# Only one index can be set in the diagram below #
scatter2 = (
 Line()
 .add_xaxis(x)
 .add_yaxis("Merchant B", [v/1000 for v in ()], yaxis_index=1)
)
(scatter2)
scatter1.render_notebook()

在这里插入图片描述

Use of secondary axes and setting of axis ranges and scale sizes, adding labels for axes

# Drawing bar graphs
bar=(
 Bar()
 .add_xaxis(['2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021'])
 .add_yaxis('Number of positions advertised', [11729, 13475, 15659, 15583, 16144, 9657, 13549, 13172])
 .add_yaxis('Number of recruits', [19538, 22249, 27817, 27061, 28533, 14537, 24128, 25726])
 
 # Setting the secondary axes
 .extend_axis(yaxis=(axislabel_opts=(formatter="{value} ten thousand"), 
          interval=30,
         max_=180,
         min_=0) # Set the interval length of the axes
    )
 #.set_series_opts(label_opts=(is_show=False))
 .set_global_opts(
  title_opts=(title="Civil service examination data for previous years", pos_right='45%'), # Set the title and position of the title
  legend_opts=(pos_right='10%', # Set the location of the legend
         #pos_top='10%',
         orient='vertical'), # The different legends are placed vertically against each other #
  #max_=40000, there is no lim parameter here, you can set it in the axes.
  
  # Setting the main axis configuration items
  yaxis_opts=(axislabel_opts=(formatter="{value} man"), 
         max_=50000)   # Setting the range of axes lim
 )

)

# Plot line graphs (also without brackets)
line = Line().add_xaxis(['2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021']).add_yaxis("Enrollment", [152, 140.9, 139.46, 148.63, 138, 137.93, 140, '-'], 
      yaxis_index=1, #Without this parameter, there are no secondary axes, which can be problematic for different magnitudes of data
      label_opts=(formatter=JsCode("function (params) {return [1] + 'Wan'}"))
      )
 
# Two shapes stacked on top of each other
(line)
("overlap_bar_line.html")
bar.render_notebook()

在这里插入图片描述

Drawing funnel diagrams

The easiest way to draw

# It's mainly the data format that's not consistent with the others #
funnel = (
 Funnel()
 .add("Mall Funnel", [ list(two_values) for two_values in zip(['Recall', 'Rough platoon', 'Elimination'], [100, 80, 10]) ])
 .set_series_opts(label_opts=(formatter="{b}: {c}substandard")) 
 .set_global_opts(title_opts=(title="Funnel analysis of request filtration."))
)
 
funnel.render_notebook()

Methods for plotting complex points

# /p/63976935 Some references
funnel = (
 Funnel(init_opts=(width="600px", height="400px")) # is width and height, not pixels
 #Funnel()
 .add("Mall Funnel", [ list(two_values) sfor two_values in zip(['Recall', 'Rough platoon', 'Elimination'], [100, 80, 10]) ])
 #.set_series_opts(label_opts=(is_show=False),
      #markpoint_opts=(data=[(type_="max", name="max"),]))
 .set_series_opts(label_opts=(formatter="{b}: {c}, {d}%")) # d is the proportion of each value to the total
 
 # Percentage Here it is recommended to pass in a new set of y data (divide each by a value) /p/63976935
 .set_global_opts(title_opts=(title="Funnel analysis of request filtration."),
     #yaxis_opts=(axislabel_opts=(formatter='{data} {value}%')) #"{value} people"
     )
)
 
funnel.render_notebook()

在这里插入图片描述

to this article on the use of python pyecharts library is introduced to this article, more related python pyecharts library content please search my previous posts or continue to browse the following related articles I hope that you will support me more in the future!