Skip to content

Scatterplot ​

Plot two neighborhood attributes with ak.Scatterplot and link click selections to the map.

Python Script ​

python
"""Scatter plot + map — click a neighborhood on the map or a dot in the plot and the other highlights it
(gallery: scatterplot-click). The file is in World Mercator meters, so its CRS is declared.
"""
from __future__ import annotations

from pathlib import Path

import pyautark as ak

DATA_DIR = Path(__file__).resolve().parents[1] / "data"

neighborhoods = ak.GeoJSON(
    "neighborhoods",
    url=(DATA_DIR / "mnt_neighs_proj.geojson").as_uri(),
    coordinate_format="EPSG:3395",
)
picked = ak.point("picked")

spec = ak.Spec(
    metadata=ak.Metadata(title="Scatter Plot Click"),
    data=[neighborhoods],
    views=[
        ak.Map(layers=[ak.Layer(neighborhoods, id="neighborhoods").style(color="#9ecae9")]),
        ak.Scatterplot(neighborhoods, x="shape_area", y="shape_leng", selection=picked, width=760),
    ],
    links=[ak.Link(picked, target="neighborhoods")],
    layout=ak.Layout(type="vertical"),
)

if __name__ == "__main__":
    spec.window(height="760px")

Run in Jupyter or standalone HTML

Replace spec.window(...) with spec.widget() inside a Jupyter notebook (requires pip install "pyautark[widget]") or spec.save_html("out.html") to export a standalone web page.

This example comes from the pyautark repository.

Released under the MIT License.