Skip to content

lvisei/PyL7Plot

Repository files navigation

English | 简体中文

PyL7Plot

🌍 Python3 binding for @AntV/L7Plot Plotting Library. Geospatial Visualization Chart Library Based on @AntV/L7. Inspired by PyG2Plot.

Latest Stable Version build Status Pypi Download

Installation

$ pip install pyl7plot

Usage

Render to HTML

from pyl7plot import Plot

dot = Plot("Dot")

dot.set_options({
  "map": {
    "type": "mapbox",
    "style": "light",
    "center": [103.447303, 31.753574],
    "zoom": 7,
  },
  "autoFit": True,
  "source": {
    "data": [
       { "lng": 103.715, "lat": 31.211, "depth": 10, "mag": 5.8, "title": "M 5.8 - eastern Sichuan, China" },
       { "lng": 104.682, "lat": 31.342, "depth": 10, "mag": 5.7, "title": "M 5.7 - eastern Sichuan, China" },
       # ...
    ],
    "parser": { "type": "json", "x": "lng", "y": "lat" },
  },
  "color": {
    "field": "mag",
    "value": ["#82cf9c", "#10b3b0", "#2033ab"],
    "scale": { "type": "quantize" },
  },
  "size": {
    "field": "mag",
  },
  "state": { "active": True },
  "scale": { "position": "bottomright" },
  "legend": { "position": "bottomleft" },
  "tooltip": {
    "items": ["title", "mag", "depth"],
  },
})

# Render html file
dot.render("dot.html")

# Or render html string
# dot.render_html()

image

Render in Jupyter

from pyl7plot import Plot, JS

dot = Plot("Dot")

dot.set_options({
  "map": {
    "type": "mapbox",
    "style": "light",
    "center": [103.447303, 31.753574],
    "zoom": 7,
  },
  "autoFit": True,
  "height": 400, # set a default height in jupyter preview
  "source": {
    "data": [
       { "lng": 103.715, "lat": 31.211, "depth": 10, "mag": 5.8, "title": "M 5.8 - eastern Sichuan, China" },
       { "lng": 104.682, "lat": 31.342, "depth": 10, "mag": 5.7, "title": "M 5.7 - eastern Sichuan, China" },
       # ...
    ],
    "parser": { "type": "json", "x": "lng", "y": "lat" },
  },
  "color": {
    "field": "mag",
    "value": ["#82cf9c", "#10b3b0", "#2033ab"],
    "scale": { "type": "quantize" },
  },
  "size": {
    "field": "mag",
    # Use JS API, you can use JavaScript syntax for callback.
    "value": JS('''function({ mag }) {
        return (mag - 4.3) * 10;
      }''')
  },
  "state": { "active": True },
  "scale": { "position": "bottomright" },
  "legend": { "position": "bottomleft" },
  "tooltip": {
    "items": ["title", "mag", "depth"],
  },
})

# Render in notebook
dot.render_notebook()

# Or render in jupyter lab
# dot.render_jupyter_lab()

More Online Examples PyL7plot in Jupyter Lab.

API

  • Plot
  1. Plot(plot_type: str): get an instance of Plot class.

  2. plot.set_options(options: object): set the options of L7Plot into instance.

  3. plot.render(path, env, **kwargs): render out html file by setting the path, jinja2 env and kwargs.

  4. plot.render_notebook(env, **kwargs): render plot on jupyter preview.

  5. plot.render_jupyter_lab(env, **kwargs): render plot on jupyter lab preview.

  6. plot.render_html(env, **kwargs): render out html string by setting jinja2 env and kwargs.

协议

MIT

Releases

No releases published

Packages

No packages published