Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use PyG2Plot Visualization Library in Python

Shulou Source: shulou.com Published: 2022-05-31 11:04:07 09月16日 Update

This article mainly explains "how to use the PyG2Plot visualization library in Python". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the PyG2Plot visualization library in Python.

How to use $pip install pyg2plot

There are two main ways to use it (welcome to mention issue in the process of capacity expansion)

1. Render a complete HTMLfrom pyg2plot import Plotline = 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 ()

This situation can be used to:

The scenario where the server html goes straight out

Generate interactive visual sharing

Scenarios embedded by tools such as Excel

two。 Preview 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") in Jupyter notebook "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

In the process of doing data analysis tutorials, our data can be visualized and previewed using PyG2Plot, which is very convenient!

Development principle

> the principle of PyG2Plot is actually very simple, which draws lessons from the implementation of pyecharts. However, because Ant Financial Services Group's G2Plot is completely based on the configuration structure of visual analysis theory, it is much simpler in encapsulation than pyecharts.

The basic principle is that when you provide API through Python syntax, and then call render, the final G2Plot HTML text is generated, and the generated HTML varies slightly for different environments.

So the core document is:

Plot.py: provides almost all the API of PyG2Plot

Engine.py: provides the ability to render HTML, which is actually based on jinjia2, a template engine, with little basic content.

Templates: all the jinjia2 template files are provided. Jinjia2 documentation is very detailed on how to use the template.

Working with documentation

The API provided by PyG2Plot is very simple to use:

# 1. Importfrom pyg2plot import Plot# 2. Use a plotline = Plot ("Line") # 3. Set_options use G2Plotline.set_options ({data,...}) # 4. Renderline.render_notebook ()

The parameters of set_options API, which completely follow the configuration document of G2Plot, support all diagrams, functions, features, concepts and structures without any modification.

Thank you for reading, the above is the content of "how to use the PyG2Plot visualization library in Python". After the study of this article, I believe you have a deeper understanding of how to use the PyG2Plot visualization library in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Visualization content principles documents templates learning generation scenarios that is situations data files structures capabilities analysis configuration differences simplicity functions parameters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi Xiaomi Linux NVidia