Bar Chart
Build a linked bar chart with ak.Barchart and ak.Link: click bars to highlight the matching neighborhoods on the map.
Python Script
python
"""Bar chart + map — one bar per neighborhood, linked to the map by click (gallery: barchart-click)."""
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="Bar Chart Click"),
data=[neighborhoods],
views=[
ak.Map(layers=[ak.Layer(neighborhoods, id="neighborhoods").style(color="#9ecae9")]),
ak.Barchart(
neighborhoods,
x="ntaname",
y="shape_area",
selection=picked,
title="Area of each neighborhood",
width=760,
margins={"left": 60, "right": 20, "top": 50, "bottom": 200},
),
],
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.