pyecharts 是一个用于生成 Echarts 图表的类库

pyecharts 是一个用于生成 Echarts 图表的类库。实际上就是 Echarts 与 Python 的对接。

Echarts 是百度开源的一个数据可视化 JS 库。看了官方的介绍文档,觉得很不错,就想看看有没有人实现了 Python 库可以直接调用的。

Github 上找到了一个 echarts-python 不过这个项目已经很久没更新且也没什么介绍文档。

借鉴了该项目,就自己动手实现一个,于是就有了 pyecharts。API 接口是从另外一个图表库 pygal 中模仿的


Python Compatibility

pyecharts works on Python2.7 and Python3.4+.

pyecharts handles all strings and files with unicode encoding and you MUST use unicode string on Python 2.


You can install it via pip

or clone it and install it

Please note: since version 0.3.2, NO LONGER pyecharts comes with any map files. Please read next section for more informations.

Geo Data extensions (0.5.7+)

From, 138,398 cities of the world with a population of at least 1000 inhabitants: echarts-cities-pypkg

Install data extensions:

Map extensions

Here is a list of map extensions from pyecharts dev team:

In order to install them, you can try one or all of them below:

Basic Usage

Render to Local Html File

It will create a file named render.html in the root directory, open file with your borwser.

pyecharts 是一个用于生成 Echarts 图表的类库

Export as Images or Pdf

pyecharts-snapshot is a command line utility and a library extension which renders the output of pyecharts as a svg, png, jpeg, gif image or a pdf file.

After you will have installed pyecharts-snapshot, you can modify previous example file slightly and get png output directly:

So please see installation instruction and other usage at that repository.

Platform Support

pyecharts exposes chart API and template API so that it can work on other python frameworks.

Integration with Jupyter Notebook/nteract


In the Notebook cell, you can simply pass on chart instance itself to Jupyter, which will diplay the chart. Please note render_notebook function has been removed.

All chart classes in pyecharts implement the _repr_html_ interface about IPython Rich Display .

In the case of online jshost mode, you can also download as some file formats (ipynb/py/html/pdf) and run without jupyter notebook enviromnment.

pyecharts 是一个用于生成 Echarts 图表的类库


Since pyecharts 0.5.5+, nteract is supported. Once the following two lines should added to your notebook, you could use pyecharts in nteract in the same way as in jupyter notebook.

pyecharts 是一个用于生成 Echarts 图表的类库

However, when rendering output as image, the instructions are the same as jupyter notebook. Only default html(including js) output should call enable_nteract().

Integrate With Web Framework

With the help of pyecharts API, it is easy to integrate pyecharts to your web projects, such as Flask and Django.


pyecharts 是一个用于生成 Echarts 图表的类库

Advanced Topics

Custom Template Files and Layout

pyecharts exposes engine API so that you can use your own template file and custom CSS.

In addition, pyecharts also ships a lot of jinja2 template functions used in template files.

Custom Map Libraries

All maps are developed and maintained by echarts-maps github organisation.

  • 发表于:
  • 原文链接
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 删除。