G2 is an open source statistical chart engine based on graph syntax and data analysis. Based on G2, G2Plot retains the powerful graphics capabilities of G2 while shielding complex concepts, and encapsulates a database of commonly used statistical charts in business.
G2PlotIs a configuration based, elegant experience, data analysis oriented statistical chart library to help developers create high-quality statistical charts at minimal cost.
So for those of you who have Python, how do you use G2Plot for visualization after data analysis? That is, how do you combine G2Plot with Python? Here is a PyG2Plot package based on G2Plot, welcome to help me fill the Star. **
How to use
$ pip install pyg2plot
Copy the code
There are two main ways to use it (capacity expansion, welcome to issue)
1. Render complete HTML
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()
Copy the code
This can be used for:
- Server side HTML straight out scenario
- Generate interactive visual sharing
- Excel and other tools embedded in the scene
2. Preview the information in the 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()
Copy the code
As we work on our data analysis tutorial, it’s very convenient to visualize and preview our data using PyG2Plot!
The development principle
The principle of PyG2Plot is actually very simple, which refers to the implementation of Pyecharts. However, because Ant Financial’s G2Plot is completely based on the configuration structure of visual analysis theory, its packaging is much, much simpler than Pyecharts.
The basic principle is to provide the API through Python syntax and then render to generate the final G2Plot HTML text, with slightly different HTML generated for different environments.
So the core file is:
- Plot.py: Provides almost all of PyG2Plot’s APIS
- Engine. Py: provides the ability to render HTML, which is based on the template engine Jinjia2
- Templates: All jinjia2 template files are provided. How do you use templates? The documentation is very detailed
Using document
PyG2Plot provides a very simple API to use:
# 1. import
from pyg2plot import Plot
# 2. use a plot
line = Plot("Line")
# 3. set_options use G2Plot
line.set_options({ data, ... })
# 4. render
line.render_notebook()
Copy the code
The set_options API parameters are completely usedConfiguration documentation for G2PlotSupports all diagrams, functions, features, concepts, and structures without any change.
The last
Welcome to Star 🙇♂️
- AntV G2Plot
- PyG2Plot
Finally, any feature support and bug feedback, welcome issue or PR.