# g2py
> 🎨 g2py 是 [`@AntV/G2`](https://github.com/antvis/G2) 在 Python3 上的封装。与 G2Plot采用同样的方式进行封装
[![Latest Stable Version](https://img.shields.io/pypi/v/g2py.svg)](https://pypi.python.org/pypi/g2py)
[![Pypi Download](https://img.shields.io/pypi/dm/g2py)](https://pypi.python.org/pypi/g2py)
<div align="center">
<img src="https://free.wzznft.com/i/2023/10/19/u4chtb.png" width="800">
</div>
**相关文档**: [English README](./README.md) · [绘制常用统计图表](./docs/plot.md) · [在 Jupyter 中使用](./docs/jupyter.md) · [技术原理](./docs/how.md)
## 安装
```bash
$ pip install g2py
```
## 使用
#### **渲染成 HTML**
```py
from g2py import Plot
chart10 = Plot("Chart")
chart10.set_options({
"type": "density",
"autoFit": "true",
"data": {
"type": "fetch",
"value": "https://assets.antv.antgroup.com/g2/species.json",
"transform": [{"type": "kde", "field": "y", "groupBy": ["x"], "size": 20 }],
},
"encode": { "x": "x", "y": "y", "color": "x", "size": "size" },
"tooltip": 'true',
})
# 1. 渲染成 html 文件
chart10.render("plot.html")
# 2. 渲染成 html 字符串
chart10.render_html()
```
#### **在 Jupyter 中使用**
```py
from g2py import Plot
chart10 = Plot("Chart")
chart10.set_options({
"type": "density",
"autoFit": "true",
"data": {
"type": "fetch",
"value": "https://assets.antv.antgroup.com/g2/species.json",
"transform": [{"type": "kde", "field": "y", "groupBy": ["x"], "size": 20 }],
},
"encode": { "x": "x", "y": "y", "color": "x", "size": "size" },
"tooltip": 'true',
})
chart10.render_notebook()
chart10.render_jupyter_lab()
```
```
使用 `JS` 方法,你可以创建一个 JavaScript 的代码片段去处理各种回调方法属性。
## API
目前 `g2py` 只提供简单的一个 API。
- **Plot**
1. *Plot(plot_type: str)*: 获取 `Plot` 对应的类实例。
2. *plot.set_options(options: object)*: 给图表实例设置一个 [G2](https://g2.antv.antgroup.com/) 图形的配置,文档可以直接参考 G2 官网,未进行任何二次数据结构包装。
3. *plot.render(path, env, **kwargs)*: 渲染出一个 HTML 文件,同时可以传入文件的路径,以及 jinja2 env 和 kwargs 参数。
4. *plot.render_notebook(env, **kwargs)*: 将图形渲染到 jupyter 的预览。
5. *plot.render_jupyter_lab(env, **kwargs)*: 将图形渲染到 jupyter lab 的预览。
6. *plot.render_html(env, **kwargs)*: 渲染出 HTML 字符串,同时可以传入 jinja2 env 和 kwargs 参数。
7. *plot.dump_js_options(env, **kwargs)*: 输出 Javascript 的 option 配置结构,同时可以传入 jinja2 env 和 kwargs 参数,可以用于 Server 中的 HTTP 结构返回数据结构。
Raw data
{
"_id": null,
"home_page": "https://github.com/2017kevinwu/",
"name": "g2py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "AntV,G2,charts,g2py,visualization",
"author": "kevin",
"author_email": "1357690472@qq.com",
"download_url": "https://files.pythonhosted.org/packages/65/2e/37dcae932e549a580ddabea37f20274ac5ea1df1ca2e3240b4d06484b0dc/g2py-0.1.2.tar.gz",
"platform": null,
"description": "# g2py\r\n\r\n> \ud83c\udfa8 g2py \u662f [`@AntV/G2`](https://github.com/antvis/G2) \u5728 Python3 \u4e0a\u7684\u5c01\u88c5\u3002\u4e0e G2Plot\u91c7\u7528\u540c\u6837\u7684\u65b9\u5f0f\u8fdb\u884c\u5c01\u88c5 \r\n\r\n[![Latest Stable Version](https://img.shields.io/pypi/v/g2py.svg)](https://pypi.python.org/pypi/g2py)\r\n[![Pypi Download](https://img.shields.io/pypi/dm/g2py)](https://pypi.python.org/pypi/g2py)\r\n\r\n\r\n<div align=\"center\">\r\n <img src=\"https://free.wzznft.com/i/2023/10/19/u4chtb.png\" width=\"800\">\r\n</div>\r\n\r\n\r\n**\u76f8\u5173\u6587\u6863**\uff1a [English README](./README.md) \u00b7 [\u7ed8\u5236\u5e38\u7528\u7edf\u8ba1\u56fe\u8868](./docs/plot.md) \u00b7 [\u5728 Jupyter \u4e2d\u4f7f\u7528](./docs/jupyter.md) \u00b7 [\u6280\u672f\u539f\u7406](./docs/how.md)\r\n\r\n## \u5b89\u88c5\r\n\r\n```bash\r\n$ pip install g2py\r\n```\r\n\r\n\r\n## \u4f7f\u7528\r\n\r\n#### **\u6e32\u67d3\u6210 HTML**\r\n\r\n```py\r\n\r\n\r\nfrom g2py import Plot\r\nchart10 = Plot(\"Chart\")\r\nchart10.set_options({\r\n \"type\": \"density\",\r\n \"autoFit\": \"true\",\r\n \"data\": {\r\n \"type\": \"fetch\",\r\n \"value\": \"https://assets.antv.antgroup.com/g2/species.json\",\r\n \"transform\": [{\"type\": \"kde\", \"field\": \"y\", \"groupBy\": [\"x\"], \"size\": 20 }],\r\n },\r\n \"encode\": { \"x\": \"x\", \"y\": \"y\", \"color\": \"x\", \"size\": \"size\" },\r\n \"tooltip\": 'true',\r\n})\r\n\r\n# 1. \u6e32\u67d3\u6210 html \u6587\u4ef6\r\nchart10.render(\"plot.html\")\r\n# 2. \u6e32\u67d3\u6210 html \u5b57\u7b26\u4e32\r\nchart10.render_html()\r\n```\r\n\r\n\r\n#### **\u5728 Jupyter \u4e2d\u4f7f\u7528**\r\n\r\n```py\r\nfrom g2py import Plot\r\nchart10 = Plot(\"Chart\")\r\nchart10.set_options({\r\n \"type\": \"density\",\r\n \"autoFit\": \"true\",\r\n \"data\": {\r\n \"type\": \"fetch\",\r\n \"value\": \"https://assets.antv.antgroup.com/g2/species.json\",\r\n \"transform\": [{\"type\": \"kde\", \"field\": \"y\", \"groupBy\": [\"x\"], \"size\": 20 }],\r\n },\r\n \"encode\": { \"x\": \"x\", \"y\": \"y\", \"color\": \"x\", \"size\": \"size\" },\r\n \"tooltip\": 'true',\r\n})\r\n\r\n\r\nchart10.render_notebook()\r\n\r\nchart10.render_jupyter_lab()\r\n```\r\n```\r\n\r\n\r\n\r\n\u4f7f\u7528 `JS` \u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a JavaScript \u7684\u4ee3\u7801\u7247\u6bb5\u53bb\u5904\u7406\u5404\u79cd\u56de\u8c03\u65b9\u6cd5\u5c5e\u6027\u3002\r\n\r\n\r\n## API\r\n\r\n\u76ee\u524d `g2py` \u53ea\u63d0\u4f9b\u7b80\u5355\u7684\u4e00\u4e2a API\u3002\r\n\r\n - **Plot**\r\n\r\n1. *Plot(plot_type: str)*: \u83b7\u53d6 `Plot` \u5bf9\u5e94\u7684\u7c7b\u5b9e\u4f8b\u3002\r\n\r\n2. *plot.set_options(options: object)*: \u7ed9\u56fe\u8868\u5b9e\u4f8b\u8bbe\u7f6e\u4e00\u4e2a [G2](https://g2.antv.antgroup.com/) \u56fe\u5f62\u7684\u914d\u7f6e\uff0c\u6587\u6863\u53ef\u4ee5\u76f4\u63a5\u53c2\u8003 G2 \u5b98\u7f51\uff0c\u672a\u8fdb\u884c\u4efb\u4f55\u4e8c\u6b21\u6570\u636e\u7ed3\u6784\u5305\u88c5\u3002\r\n\r\n3. *plot.render(path, env, **kwargs)*: \u6e32\u67d3\u51fa\u4e00\u4e2a HTML \u6587\u4ef6\uff0c\u540c\u65f6\u53ef\u4ee5\u4f20\u5165\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u4ee5\u53ca jinja2 env \u548c kwargs \u53c2\u6570\u3002\r\n\r\n4. *plot.render_notebook(env, **kwargs)*: \u5c06\u56fe\u5f62\u6e32\u67d3\u5230 jupyter \u7684\u9884\u89c8\u3002\r\n\r\n5. *plot.render_jupyter_lab(env, **kwargs)*: \u5c06\u56fe\u5f62\u6e32\u67d3\u5230 jupyter lab \u7684\u9884\u89c8\u3002\r\n\r\n6. *plot.render_html(env, **kwargs)*: \u6e32\u67d3\u51fa HTML \u5b57\u7b26\u4e32\uff0c\u540c\u65f6\u53ef\u4ee5\u4f20\u5165 jinja2 env \u548c kwargs \u53c2\u6570\u3002\r\n\r\n7. *plot.dump_js_options(env, **kwargs)*: \u8f93\u51fa Javascript \u7684 option \u914d\u7f6e\u7ed3\u6784\uff0c\u540c\u65f6\u53ef\u4ee5\u4f20\u5165 jinja2 env \u548c kwargs \u53c2\u6570\uff0c\u53ef\u4ee5\u7528\u4e8e Server \u4e2d\u7684 HTTP \u7ed3\u6784\u8fd4\u56de\u6570\u636e\u7ed3\u6784\u3002\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python3 binding for `@AntV/G2` Plotting Library, make charting easier.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/2017kevinwu/"
},
"split_keywords": [
"antv",
"g2",
"charts",
"g2py",
"visualization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9a6dc7b27746f89522cc4d9c24baa645421625e42ec101737a7e135e4423f4e7",
"md5": "4ef7ba39de3f428d67ce96046691007c",
"sha256": "b91e05425cc83747ad35de7a171230a4e1c440a3262c21c907516ee589ac8cc0"
},
"downloads": -1,
"filename": "g2py-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4ef7ba39de3f428d67ce96046691007c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7772,
"upload_time": "2023-10-25T06:15:45",
"upload_time_iso_8601": "2023-10-25T06:15:45.232799Z",
"url": "https://files.pythonhosted.org/packages/9a/6d/c7b27746f89522cc4d9c24baa645421625e42ec101737a7e135e4423f4e7/g2py-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "652e37dcae932e549a580ddabea37f20274ac5ea1df1ca2e3240b4d06484b0dc",
"md5": "e61eda730699e30a8e86cdd0d3945089",
"sha256": "a66ae68dff0ecc9ad216ca19c548afc2ee73c8d8355c5624d2e5287117831752"
},
"downloads": -1,
"filename": "g2py-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "e61eda730699e30a8e86cdd0d3945089",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8189,
"upload_time": "2023-10-25T06:15:47",
"upload_time_iso_8601": "2023-10-25T06:15:47.758445Z",
"url": "https://files.pythonhosted.org/packages/65/2e/37dcae932e549a580ddabea37f20274ac5ea1df1ca2e3240b4d06484b0dc/g2py-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-25 06:15:47",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "g2py"
}