网络编程
位置:首页>> 网络编程>> Python编程>> python pyg2plot的原理知识点总结

python pyg2plot的原理知识点总结

作者:小妮浅浅  发布时间:2021-03-27 23:13:51 

标签:python,pyg2plot

1、说明

PyG2Plot 原理其实非常简单,其中借鉴了 pyecharts 的实现,但是因为蚂蚁金服的 G2Plot 完全基于可视分析理论的配置式结构,所以封装上比 pyecharts 简洁非常非常多。

基本的原理,就是通过 Python 语法提供 API,然后再调用 render 的时候,生成最终的 G2Plot HTML 文本,而针对不同的环境,生成的 HTML 稍有区别。

2、核心文件

  • plot.py: 提供了 PyG2Plot 的几乎全部 API

  • engine.py:提供了渲染 HTML 的能力,其实是基于 jinjia2 这个模板引擎实现的,基本内容很少

  • templates:提供了所有的 jinjia2 模板文件,对于模板怎么用,jinjia2 的文档是非常非常详细的

知识点扩展:

python中pyg2plot如何使用

1、渲染出完整的 HTML

这种情况可以用于:

服务端 html 直出的场景

生成可交互可视化分享

Excel 等工具嵌入的场景


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 named plot.html
line.render("plot.html")
# 2. render html string
line.render_html()

2、在 Jupyter notebook 中预览


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",
})
line.render_notebook()

来源:https://www.py.cn/jishu/jichu/27140.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com