Choropleth Data Link#
Download this notebook from GitHub (right-click to download).
import holoviews as hv
from holoviews import opts
from holoviews.plotting.links import DataLink
hv.extension('bokeh')
This example demonstrates how to use a DataLink to join two elements displaying the same data, a choropleth of the Texas unemployment rate alongside a Table of the same data. By linking the two selecting a polygon will highlight it in the table and vice versa.
Declare data#
from bokeh.sampledata.us_counties import data as counties
from bokeh.sampledata.unemployment import data as unemployment
counties = [dict(county, Unemployment=unemployment[cid])
for cid, county in counties.items()
if county["state"] == "tx"]
detailed_name = 'detailed_name' if counties[0].get('detailed_name') else 'detailed name' # detailed name was changed in Bokeh 3.0
county_data = [(county[detailed_name], county['Unemployment']) for county in counties]
choropleth = hv.Polygons(counties, ['lons', 'lats'], [(detailed_name, 'County'), 'Unemployment'], label='Texas Unemployment')
table = hv.Table(county_data, [(detailed_name, 'County'), 'Unemployment'])
print(len(choropleth.data), len(table))
254 254
Declare Plot#
As shown above the two elements have the same length meaning that they can be linked. Linking the data in this way allows cross-selecting, e.g. by selecting one or more rows in the Table
we can see the polygon for the county highlight in the choropleth:
# Link the choropleth and the table
DataLink(choropleth, table)
(choropleth + table).opts(
opts.Table(height=428),
opts.Polygons(width=500, height=500, tools=['hover', 'tap'], xaxis=None,
yaxis=None, color_index='Unemployment'))
WARNING:param.PolygonPlot: The `color_index` parameter is deprecated in favor of color style mapping, e.g. `color=dim('color')` or `line_color=dim('color')`
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.
Download this notebook from GitHub (right-click to download).