Python pyecharts Module
pyecharts is a Python data visualization library based on ECharts, allowing users to generate various types of interactive charts and data visualizations using the Python language.
ECharts is an open-source visualization library implemented in JavaScript, and Pyecharts is a Python wrapper for ECharts, making it more convenient to use ECharts in Python.
pyecharts provides a set of simple and flexible APIs that enable users to easily create various charts including but not limited to line charts, bar charts, scatter plots, pie charts, maps, etc.
With pyecharts, users can process and prepare data using the Python language, and then use concise code to generate interactive charts that can be embedded in web applications or saved as static files.
pyecharts Features and Functions:
-
Easy to Use: Pyecharts provides an intuitive and friendly API, allowing users to quickly get started and easily generate various charts.
-
Rich Chart Types: Supports a variety of common chart types, including line charts, bar charts, scatter plots, pie charts, maps, etc., meeting the needs of different scenarios.
-
Supports Mainstream Data Formats: Capable of handling common data formats such as lists, dictionaries, Pandas DataFrames, etc.
-
Interactivity: Generated charts can be interactive, allowing users to interact with charts through mouse hovering, zooming, etc.
-
Rich Configuration Options: Provides rich configuration options, allowing users to customize chart styles, layouts, and other properties.
-
Theme Support: Provides multiple themes, allowing users to choose the appropriate theme to make charts more consistent with the overall style of the application.
pyecharts Installation
Section titled “pyecharts Installation”pip installation:
Source installation:
After successful installation, you can check the pyecharts version:
Output is as follows:
pyecharts Chart Types
Section titled “pyecharts Chart Types”pyecharts supports the following chart types:
| Chart Type | pyecharts Class | Import |
|---|---|---|
| Line Chart | Line |
from pyecharts.charts import Line |
| Bar Chart | Bar |
from pyecharts.charts import Bar |
| Scatter Plot | Scatter |
from pyecharts.charts import Scatter |
| Pie Chart | Pie |
from pyecharts.charts import Pie |
| Radar Chart | Radar |
from pyecharts.charts import Radar |
| Heatmap | HeatMap |
from pyecharts.charts import HeatMap |
| K-line Chart | Kline |
from pyecharts.charts import Kline |
| Box Plot | Boxplot |
from pyecharts.charts import Boxplot |
| Map | Map |
from pyecharts.charts import Map |
| Word Cloud | WordCloud |
from pyecharts.charts import WordCloud |
| Gauge | Gauge |
from pyecharts.charts import Gauge |
| Funnel Chart | Funnel |
from pyecharts.charts import Funnel |
| Tree Chart | Tree |
from pyecharts.charts import Tree |
| Parallel Coordinates | Parallel |
from pyecharts.charts import Parallel |
| Sankey Diagram | Sankey |
from pyecharts.charts import Sankey |
| Geo Chart | Geo |
from pyecharts.charts import Geo |
| Timeline | Timeline |
from pyecharts.charts import Timeline |
| 3D Scatter Plot | Scatter3D |
from pyecharts.charts import Scatter3D |
| 3D Bar Chart | Bar3D |
from pyecharts.charts import Bar3D |
| 3D Surface Plot | Surface3D |
from pyecharts.charts import Surface3D |
Creating Your First Chart
Section titled “Creating Your First Chart”Next, we use Pyecharts to create a simple bar chart showing sales for five months:
Example
Section titled “Example”If no file path is specified in bar_chart.render(), Pyecharts will by default generate a file named “render.html” in the current working directory, meaning the generated chart will be saved in the “render.html” file.
The execution result of the above code is:

If you want the chart file name to have a certain convention or want to specify a save path, you can provide a file path parameter in the render() method. For example:
This way, the generated chart will be saved in the “my_bar_chart.html” file in the current working directory.
Setting Chart Configuration Options
In the example, the chart title is “Monthly Sales Bar Chart”, the horizontal axis is the month, and the vertical axis is sales. You can adjust the data and chart configuration according to actual needs:
Example
Section titled “Example”Description:
Bar(): Creates a bar chart object.add_xaxisandadd_yaxis: Used to add horizontal and vertical axis data respectively.set_global_opts: Configures global options, including title, axis names, etc.
The generated chart will be saved as the “bar_chart.html” file. You can open this file in a browser to view the generated bar chart.

Using Themes
Section titled “Using Themes”pyecharts supports theme switching, allowing users to choose the appropriate theme to change the chart style according to their needs.
pyecharts provides 10+ built-in themes, and developers can also customize their preferred themes.
The following is a simple example demonstrating how to switch themes in pyecharts:
Example
Section titled “Example”The above example demonstrates how to use ThemeType in pyecharts to switch themes. The theme types supported by pyecharts include LIGHT, DARK, etc. You can choose the appropriate theme according to your needs.
init_opts=opts.InitOpts(theme=ThemeType.LIGHT): When creating a chart object, specify the initial theme of the chart through theinit_optsparameter. Here it is set to light.
The generated chart is as follows:

The following is the list of themes supported by pyecharts:
Light Themes:
"LIGHT": Default light theme"WESTEROS": Classic warm-tone theme"CHALK": Chalk-style theme"ESSOS": Mild green-tone theme"INFOGRAPHIC": Infographic theme"MACARONS": Delicious candy-color theme
Dark Themes:
"DARK": Default dark theme"PURPLE-PASSION": Deep purple-tone theme"SHINE": Simple black-tone theme"VINTAGE": Vintage-style theme"ROMA": Ancient Roman-style theme"WALDEN": Forest dark-tone theme
Users can create custom themes by setting custom colors and styles.
Setting Global Configuration Options
Section titled “Setting Global Configuration Options”set_global_opts is a method in pyecharts used to set global configuration options. This method allows you to configure some global properties of the entire chart, such as title, axes, legend, etc.
The following are some commonly used global configuration options:
Description:
title_opts: Title configuration options, can set the main title and subtitle, as well as related style settings.xaxis_optsandyaxis_opts: x-axis and y-axis configuration options, can set axis names, axis line styles, etc.legend_opts: Legend configuration options, can set legend position, style, etc.toolbox_opts: Toolbox configuration options, used to add some interactive tools, such as save as image, data view, etc.tooltip_opts: Tooltip configuration options, can set tooltip trigger method, style, etc.
Example
Section titled “Example”The generated chart is as follows:

For more pyecharts module content, refer to: https://pyecharts.org/#/zh-cn/intro