Python Pyecharts
## Python3.x Python pyecharts Module
pyecharts is a Python data visualization library based on ECharts, which allows users to use Python language to generate various types of interactive charts and data visualizations.
ECharts is an open-source visualization library implemented using JavaScript, and Pyecharts is the Python wrapper for ECharts, making it more convenient to use ECharts in Python.
pyecharts provides a set of simple and flexible APIs, enabling users to easily create various charts, including but not limited to line charts, bar charts, scatter plots, pie charts, maps, etc.
Through pyecharts, users can use Python language to process and prepare data, then generate interactive charts with concise code. These charts can be embedded in web applications or saved as static files.
**pyecharts Features and Functions:**
* **Easy to Use:** Pyecharts provides an intuitive and user-friendly API, allowing users to quickly get started and easily generate various charts.
* **Rich Chart Types:** Supports multiple common chart types, including line charts, bar charts, scatter plots, pie charts, maps, etc., to meet different scenario requirements.
* **Supports Mainstream Data Formats:** Can handle common data formats such as lists, dictionaries, Pandas DataFrame, etc.
* **Interactivity:** Generated charts can be interactive, allowing users to interact with charts through mouse hovering, zooming, and other methods.
* **Rich Configuration Options:** Provides rich configuration options, allowing users to customize chart styles, layouts, and other properties.
* **Supports Themes:** Provides multiple themes, and users can choose appropriate themes according to their needs to make charts more consistent with the overall style of the application.
### pyecharts Installation
pip installation:
pip install pyecharts
Source installation:
$ git clone https://github.com/pyecharts/pyecharts.git $ cd pyecharts $ pip install -r requirements.txt $ python setup.py install # or execute python install.py
After successful installation, you can check the pyecharts version:
import pyecharts print(pyecharts. __version__ )
The output is as follows:
2.0.4
### pyecharts Chart Types
pyecharts supports the following chart types:
| Chart Type | pyecharts Class | Package 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` |
| Heat Map | `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 | `Funnel` | `from pyecharts.charts import Funnel` |
| Tree | `Tree` | `from pyecharts.charts import Tree` |
| Parallel Coordinates | `Parallel` | `from pyecharts.charts import Parallel` |
| Sankey | `Sankey` | `from pyecharts.charts import Sankey` |
| Geo Coordinates | `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 Chart | `Surface3D` | `from pyecharts.charts import Surface3D` |
### Create Your First Chart
Next, we use Pyecharts to create a simple bar chart showing sales for five months:
## Example
from pyecharts.charts import Bar
# Prepare data
x_data =['January','February','March','April','May']
y_data =[10,20,15,25,30]
# Create bar chart
bar_chart = Bar()
bar_chart.add_xaxis(x_data)
bar_chart.add_yaxis("Sales", y_data)
# You can also pass a path parameter, e.g., bar_chart.render("bar_chart.html")
bar_chart.render()
If you do not specify a file path 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.
Executing the above code results in:
!(
YouTip