python pyg2plot的原理知識點總結
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.htmlline.render('plot.html')# 2. render html stringline.render_html()
2、在 Jupyter notebook 中預覽
from pyg2plot import Plotline = 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()
到此這篇關于python pyg2plot的原理知識點總結的文章就介紹到這了,更多相關python pyg2plot的原理內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
