python pyg2plot的原理知识点总结

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

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

标签:python,pyg2plot
0
投稿

猜你喜欢

  • Python使用StringIO和BytesIO读写内存数据

    2022-06-15 02:45:45
  • python+selenium实现简历自动刷新的示例代码

    2023-11-27 16:13:01
  • Python 正则表达式大全(推荐)

    2021-10-02 05:43:50
  • python随机获取列表中某一元素的方法

    2023-08-23 18:25:13
  • Python中的条件判断语句基础学习教程

    2021-06-19 11:51:36
  • python GUI库图形界面开发之PyQt5信号与槽事件处理机制详细介绍与实例解析

    2021-03-23 03:49:14
  • Python request设置HTTPS代理代码解析

    2023-01-15 00:48:24
  • 如何在python中判断变量的类型

    2022-05-03 03:35:06
  • 如何在windows下安装Pycham2020软件(方法步骤详解)

    2023-05-19 14:07:30
  • Python基于贪心算法解决背包问题示例

    2022-10-31 01:25:56
  • Python正则表达式的应用详解

    2023-07-29 21:58:51
  • Python catplot函数自定义颜色的方法

    2021-01-29 16:25:01
  • 如何修改MySQL 5.1 data文件夹路径

    2010-10-25 19:58:00
  • TensorFlow的权值更新方法

    2022-12-24 21:41:08
  • 利用python爬取m3u8格式视频的具体实现

    2021-04-10 21:45:09
  • python实现双色球随机选号

    2021-06-26 05:11:09
  • Python递归函数特点及原理解析

    2023-12-02 19:40:40
  • python字符串格式化方式解析

    2021-06-22 14:01:46
  • 简单说明Python中的装饰器的用法

    2022-01-30 21:57:32
  • python中几种自动微分库解析

    2022-12-20 18:24:02
  • asp之家 网络编程 m.aspxhome.com