Using pyecharts in Python to Create Interactive Charts
This article introduces the Python library pyecharts, explains its background from ECharts, shows how to install it, and provides step‑by‑step examples—including creating bar and pie charts from Chengdu statistical data—while detailing the underlying code and rendering process for effective data visualization.
In the world of data presentation, visual patterns often convey information more powerfully than text; this article demonstrates how to transform data into visual charts using Python.
pyecharts is the Python implementation of Apache ECharts, a JavaScript visualization library; it wraps ECharts functionality in a Python package that generates HTML files containing the necessary JS code. To install, run pip install pyecharts , which works with Python 3.6+ and the current version is 1.7.1.
Creating a basic chart involves importing the desired chart class (e.g., Bar ), adding X‑axis and Y‑axis data with add_xaxis() and add_yaxis() , and calling render() to produce a render.html file that displays the chart in a browser. The article explains each step and shows the resulting HTML/JS output.
For a real‑world case the author uses Chengdu’s 2019 statistical yearbook data to plot per‑capita GDP and resident savings balance as bar charts, demonstrating how to replace the data vectors while keeping the same chart structure.
A pie chart example illustrates population gender ratios; it introduces the opts module for global options, uses zip() to pair labels with values, and calls add() and render() (outputting pie.html ) to generate the visualization.
The author notes that multiple charts can be combined on a single page by wrapping each chart’s code in separate functions and rendering them together, and shows a final screenshot of the combined output.
Finally, the article encourages exploring more advanced chart types such as maps and custom visual effects to further enrich data presentation.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.