🎨 Python3 binding for `@AntV/G2Plot` Plotting Library .

Overview

PyG2Plot

🎨 Python3 binding for @AntV/G2Plot which an interactive and responsive charting library. Based on the grammar of graphics, you can easily make superior statistical charts through a few lines of code. PyG2Plot is inspired by pyecharts.

Latest Stable Version build Status

Document中文说明文档 · Drawing statistical plots · In Jupyter Notebook · Principles

Installation

$ pip install pyg2plot

Usage

render HTML

from pyg2plot import Plot

line = Plot("Line")

line.set_options({
  "data": [
    { "year": "1991", "value": 3 },
    { "year": "1992", "value": 4 },
    { "year": "1993", "value": 3.5 },
    { "year": "1994", "value": 5 },
    { "year": "1995", "value": 4.9 },
    { "year": "1996", "value": 6 },
    { "year": "1997", "value": 7 },
    { "year": "1998", "value": 9 },
    { "year": "1999", "value": 13 },
  ],
  "xField": "year",
  "yField": "value",
})

# 1. render html file
line.render("plot.html")
# 2. render html string
line.render_html()

image

render Jupyter

from pyg2plot import Plot

line = Plot("Line")

line.set_options({
  "height": 400, # set a default height in jupyter preview
  "data": [
    { "year": "1991", "value": 3 },
    { "year": "1992", "value": 4 },
    { "year": "1993", "value": 3.5 },
    { "year": "1994", "value": 5 },
    { "year": "1995", "value": 4.9 },
    { "year": "1996", "value": 6 },
    { "year": "1997", "value": 7 },
    { "year": "1998", "value": 9 },
    { "year": "1999", "value": 13 },
  ],
  "xField": "year",
  "yField": "value",
})

# 1. render in notebook
line.render_notebook()

# 2. render in jupyter lab
line.render_jupyter_lab()

API

Now, only has one API of pyg2plot.

  • Plot
  1. Plot(plot_type: str): get an instance of Plot class.

  2. plot.set_options(options: object): set the options of G2Plot into instance.

  3. plot.render(path, env, **kwargs): render out html file by setting the path, jinja2 env and kwargs.

  4. plot.render_notebook(env, **kwargs): render plot on jupyter preview.

  5. plot.render_html(env, **kwargs): render out html string by setting jinja2 env and kwargs.

  6. plot.dump_js_options(env, **kwargs): dump js options by setting jinja2 env and kwargs, use it for HTTP request.

More apis is on the way.

License

MIT@hustcc.

Comments
  • python如何实现JS回调方法

    python如何实现JS回调方法

    from pyg2plot import Plot, JS

    line = Plot("Line")

    line.set_options({ "height": 400, # set a default height in jupyter preview "data": [ { "year": "1991", "value": 3 }, { "year": "1992", "value": 4 }, { "year": "1993", "value": 3.5 }, { "year": "1994", "value": 5 }, { "year": "1995", "value": 4.9 }, { "year": "1996", "value": 6 }, { "year": "1997", "value": 7 }, { "year": "1998", "value": 9 }, { "year": "1999", "value": 13 }, ], "xField": "year", "yField": "value", "lineStye": JS('''function() { return { stroke: 'red' }; }''') 这里面的JS方法该怎么写呢,有没有一个示例。

    opened by Eymecoo 1
  • feat: add JS api

    feat: add JS api

    from pyg2plot import Plot, JS
    
    line = Plot("Line")
    line.set_options({
      "height": 400, # set a default height in jupyter preview
      "data": [
        { "year": "1991", "value": 3 },
        { "year": "1992", "value": 4 },
        { "year": "1993", "value": 3.5 },
        { "year": "1994", "value": 5 },
        { "year": "1995", "value": 4.9 },
        { "year": "1996", "value": 6 },
        { "year": "1997", "value": 7 },
        { "year": "1998", "value": 9 },
        { "year": "1999", "value": 13 },
      ],
      "xField": "year",
      "yField": "value",
      "lineStye": JS('''function() {
        return { stroke: 'red' }; 
      }''')
    })
    
    opened by hustcc 1
  • 我搞错了,忽略……

    我搞错了,忽略……

    代码如下:

    from pyg2plot import Plot, JS

    line = Plot("Line")

    line.set_options({ "height": 400, # set a default height in jupyter preview "data": [ { "year": "1991", "value": 3 }, { "year": "1992", "value": 4 }, { "year": "1993", "value": 3.5 }, { "year": "1994", "value": 5 }, { "year": "1995", "value": 4.9 }, { "year": "1996", "value": 6 }, { "year": "1997", "value": 7 }, { "year": "1998", "value": 9 }, { "year": "1999", "value": 13 }, ], "xField": "year", "yField": "value", "lineStye": JS('''function() { return { stroke: 'red' }; }''') })

    1. 渲染到 notebook

    line.render_notebook()

    opened by ciwind 0
  • selenium.common.exceptions.JavascriptException: Message: javascript error: echarts is not defined

    selenium.common.exceptions.JavascriptException: Message: javascript error: echarts is not defined

    使用from snapshot_selenium import snapshot将得到的html转为图片,报错, 使用方法为pyecharts.render.make_snapshot(snapshot_selenium.snapshot, 'xxx.html', 'xxx.png')

    Traceback (most recent call last):
      File "/home/tests/test_1.py", line 20, in <module>
        make_snapshot(snapshot, '/home/plot.html', "bar0.png")
      File "/usr/local/lib/python3.8/dist-packages/pyecharts/render/snapshot.py", line 32, in make_snapshot
        content = engine.make_snapshot(
      File "/usr/local/lib/python3.8/dist-packages/snapshot_selenium/snapshot.py", line 52, in make_snapshot
        return driver.execute_script(snapshot_js)
      File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 491, in execute_script
        return self.execute(command, {
      File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 428, in execute
        self.error_handler.check_response(response)
      File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.JavascriptException: Message: javascript error: echarts is not defined
      (Session info: headless chrome=104.0.5112.101)
    Stacktrace:
    #0 0x557451a50403 <unknown>
    #1 0x557451856778 <unknown>
    #2 0x557451859617 <unknown>
    #3 0x5574518594c4 <unknown>
    #4 0x55745185a07d <unknown>
    #5 0x5574518bf853 <unknown>
    #6 0x5574518aba02 <unknown>
    #7 0x5574518bec74 <unknown>
    #8 0x5574518ab8f3 <unknown>
    #9 0x5574518810d8 <unknown>
    #10 0x557451882205 <unknown>
    #11 0x557451a97e3d <unknown>
    #12 0x557451a9adb6 <unknown>
    #13 0x557451a8113e <unknown>
    #14 0x557451a9b9b5 <unknown>
    #15 0x557451a75970 <unknown>
    #16 0x557451ab8228 <unknown>
    #17 0x557451ab83bf <unknown>
    #18 0x557451ad2abe <unknown>
    #19 0x7f7f5964f609 <unknown>
    
    opened by Frankcsc 0
  • 【BUG】无法从“markupsafe”导入名称“soft_unicode”

    【BUG】无法从“markupsafe”导入名称“soft_unicode”

    Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

    from pyg2plot import Plot Traceback (most recent call last): File "", line 1, in File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\pyg2plot_init_.py", line 9, in from pyg2plot.plot import Plot # noqa File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\pyg2plot\plot.py", line 9, in from jinja2 import Environment File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2_init_.py", line 12, in from .environment import Environment File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2\environment.py", line 25, in from .defaults import BLOCK_END_STRING File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2\defaults.py", line 3, in from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401 File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2\filters.py", line 13, in from markupsafe import soft_unicode ImportError: cannot import name 'soft_unicode' from 'markupsafe' (C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\markupsafe_init_.py)

    import pyg2plot Traceback (most recent call last): File "", line 1, in File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\pyg2plot_init_.py", line 9, in from pyg2plot.plot import Plot # noqa File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\pyg2plot\plot.py", line 9, in from jinja2 import Environment File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2_init_.py", line 12, in from .environment import Environment File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2\environment.py", line 25, in from .defaults import BLOCK_END_STRING File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2\defaults.py", line 3, in from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401 File "C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\jinja2\filters.py", line 13, in from markupsafe import soft_unicode ImportError: cannot import name 'soft_unicode' from 'markupsafe' (C:\Users\梦云之家\AppData\Roaming\Python\Python310\site-packages\markupsafe_init_.py)

    opened by mxlbb 2
Owner
hustcc
@alipay 内推,参入可视化开源项目,请加个人微信:AnyPlot。
hustcc
An intuitive library to add plotting functionality to scikit-learn objects.

Welcome to Scikit-plot Single line functions for detailed visualizations The quickest and easiest way to go from analysis... ...to this. Scikit-plot i

Reiichiro Nakano 2.3k Dec 31, 2022
NorthPitch is a python soccer plotting library that sits on top of Matplotlib

NorthPitch is a python soccer plotting library that sits on top of Matplotlib.

Devin Pleuler 30 Feb 22, 2022
🎨 Python Echarts Plotting Library

pyecharts Python ❤️ ECharts = pyecharts English README ?? 简介 Apache ECharts (incubating) 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。而 Python 是一门富有表达

pyecharts 13.1k Jan 3, 2023
Plotting library for IPython/Jupyter notebooks

bqplot 2-D plotting library for Project Jupyter Introduction bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar

null 3.4k Dec 30, 2022
:small_red_triangle: Ternary plotting library for python with matplotlib

python-ternary This is a plotting library for use with matplotlib to make ternary plots plots in the two dimensional simplex projected onto a two dime

Marc 611 Dec 29, 2022
An open-source plotting library for statistical data.

Lets-Plot Lets-Plot is an open-source plotting library for statistical data. It is implemented using the Kotlin programming language. The design of Le

JetBrains 820 Jan 6, 2023
🎨 Python Echarts Plotting Library

pyecharts Python ❤️ ECharts = pyecharts English README ?? 简介 Apache ECharts (incubating) 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。而 Python 是一门富有表达

pyecharts 10.6k Feb 18, 2021
Plotting library for IPython/Jupyter notebooks

bqplot 2-D plotting library for Project Jupyter Introduction bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar

null 3k Feb 18, 2021
:small_red_triangle: Ternary plotting library for python with matplotlib

python-ternary This is a plotting library for use with matplotlib to make ternary plots plots in the two dimensional simplex projected onto a two dime

Marc 391 Feb 17, 2021
An open-source plotting library for statistical data.

Lets-Plot Lets-Plot is an open-source plotting library for statistical data. It is implemented using the Kotlin programming language. The design of Le

JetBrains 509 Feb 17, 2021
A Python library for plotting hockey rinks with Matplotlib.

Hockey Rink A Python library for plotting hockey rinks with Matplotlib. Installation pip install hockey_rink Current Rinks The following shows the cus

null 24 Jan 2, 2023
A deceptively simple plotting library for Streamlit

?? Plost A deceptively simple plotting library for Streamlit. Because you've been writing plots wrong all this time. Getting started pip install plost

Thiago Teixeira 192 Dec 29, 2022
termplotlib is a Python library for all your terminal plotting needs.

termplotlib termplotlib is a Python library for all your terminal plotting needs. It aims to work like matplotlib. Line plots For line plots, termplot

Nico Schlömer 553 Dec 30, 2022
MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

Antonio López Rivera 162 Nov 11, 2022
Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax.

PyDexter Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax. Setup $ pip install PyDexter

D3xter 31 Mar 6, 2021
matplotlib: plotting with Python

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Check out our home page for more inform

Matplotlib Developers 16.7k Jan 8, 2023
3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)

PyVista Deployment Build Status Metrics Citation License Community 3D plotting and mesh analysis through a streamlined interface for the Visualization

PyVista 1.6k Jan 8, 2023
A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews

hvPlot A high-level plotting API for the PyData ecosystem built on HoloViews. Build Status Coverage Latest dev release Latest release Docs What is it?

HoloViz 697 Jan 6, 2023
Bokeh Plotting Backend for Pandas and GeoPandas

Pandas-Bokeh provides a Bokeh plotting backend for Pandas, GeoPandas and Pyspark DataFrames, similar to the already existing Visualization feature of

Patrik Hlobil 822 Jan 7, 2023