Frontend Development 9 min read

Getting Started with pyecharts: Installation, Usage, and Chart Examples

This tutorial introduces pyecharts, a Python wrapper for Echarts, covering installation (including Tsinghua mirror), Python 2 compatibility, and step‑by‑step code examples for creating Bar, Pie, Boxplot, Line, Radar, Scatter, Grid, and Overlap charts with rendering to HTML.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Getting Started with pyecharts: Installation, Usage, and Chart Examples

pyecharts is a powerful Python library that integrates the Echarts JavaScript visualization framework, enabling developers to generate a wide range of interactive charts directly from Python code.

Installation is performed via pip install pyecharts ; due to network restrictions in some regions, the Tsinghua mirror is recommended:

<code>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts</code>

When using Python 2.x, add the future import for Unicode handling:

<code>from __future__ import unicode_literals</code>

The article provides complete code snippets for several chart types:

Bar Chart

<code>from pyecharts import Bar
columns = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
data1 = [2.0,4.9,7.0,23.2,25.6,76.7,135.6,162.2,32.6,20.0,6.4,3.3]
data2 = [2.6,5.9,9.0,26.4,28.7,70.7,175.6,182.2,48.7,18.8,6.0,2.3]
bar = Bar("柱状图", "一年的降水量与蒸发量")
bar.add("降水量", columns, data1, mark_line=["average"], mark_point=["max","min"])
bar.add("蒸发量", columns, data2, mark_line=["average"], mark_point=["max","min"])
bar.render()</code>

Pie Chart

<code>from pyecharts import Pie
pie = Pie("饼状图", "一年的降水量与蒸发量", title_pos='center', width=900)
pie.add("降水量", columns, data1, center=[25,50], is_legend_show=False)
pie.add("蒸发量", columns, data2, center=[75,50], is_legend_show=False, is_label_show=True)
pie.render()</code>

Boxplot

<code>from pyecharts import Boxplot
boxplot = Boxplot("箱形图", "一年的降水量与蒸发量")
x_axis = ['降水量','蒸发量']
y_axis = [data1, data2]
yaxis = boxplot.prepare_data(y_axis)
boxplot.add("天气统计", x_axis, yaxis)
boxplot.render()</code>

Line Chart

<code>from pyecharts import Line
line = Line("折线图", "一年的降水量与蒸发量")
line.add("降水量", columns, data1, is_label_show=True)
line.add("蒸发量", columns, data2, is_label_show=True)
line.render()</code>

Radar Chart

<code>from pyecharts import Radar
radar = Radar("雷达图", "一年的降水量与蒸发量")
radar_data1 = [[2.0,4.9,7.0,23.2,25.6,76.7,135.6,162.2,32.6,20.0,6.4,3.3]]
radar_data2 = [[2.6,5.9,9.0,26.4,28.7,70.7,175.6,182.2,48.7,18.8,6.0,2.3]]
schema = [
    ("Jan", 5), ("Feb",10), ("Mar", 10),
    ("Apr", 50), ("May", 50), ("Jun", 200),
    ("Jul", 200), ("Aug", 200), ("Sep", 50),
    ("Oct", 50), ("Nov", 10), ("Dec", 5)
]
radar.config(schema)
radar.add("降水量", radar_data1)
radar.add("蒸发量", radar_data2, item_color="#1C86EE")
radar.render()</code>

Scatter Chart

<code>from pyecharts import Scatter
scatter = Scatter("散点图", "一年的降水量与蒸发量")
scatter.add("降水量与蒸发量的散点分布", data1, data2, xaxis_name="降水量", yaxis_name="蒸发量", yaxis_name_gap=40)
scatter.render()</code>

Grid Layout

<code>from pyecharts import Grid
line = Line("折线图", "一年的降水量与蒸发量", title_top="45%")
line.add("降水量", columns, data1, is_label_show=True)
line.add("蒸发量", columns, data2, is_label_show=True)
grid = Grid()
grid.add(bar, grid_bottom="60%")
grid.add(line, grid_top="60%")
grid.render()</code>

Overlap (Bar + Line)

<code>from pyecharts import Overlap
overlap = Overlap()
bar = Bar("柱状图-折线图合并", "一年的降水量与蒸发量")
bar.add("降水量", columns, data1, mark_point=["max","min"])
bar.add("蒸发量", columns, data2, mark_point=["max","min"])
overlap.add(bar)
overlap.add(line)
overlap.render()</code>

The concluding checklist reminds readers to import the required chart modules, create chart objects, use add() to input data and configure options, and finally call render() to generate the HTML output.

Pythontutorialdata visualizationechartspyechartschart examples
Python Programming Learning Circle
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.