I’ve always wondered how you can add a hover tooltip to datashader
import pandas as pd
import hvplot.pandas
import panel as pn
import datashader as ds
import holoviews as hv
import holoviews.operation.datashader as hd
pop = pd.DataFrame(
{
"lon": [-86.75, -86.5, -86.25, -86.0],
"lat": [33.75, 34.0, 34.25, 34.5],
"population": [100, 200, 300, 400],
"R": ["A", "B", "A", "B"],
}
)
# lon_lat_to_easting_northing
pop["x"], pop["y"] = hv.util.transform.lon_lat_to_easting_northing(
pop["lon"], pop["lat"]
)
tiles = hv.element.tiles.EsriStreet()
alpha_slider = pn.widgets.FloatSlider(name="Population", start=0, end=1, step=0.1)
highlighter = hd.inspect_points.instance(streams=[hv.streams.Tap])
points = pop.hvplot.points(
"x",
"y",
datashade=True,
aggregator=ds.count_cat("R"),
dynspread=True,
height=800,
width=1000,
)
highlight = highlighter(points).opts(
color="white", tools=["hover"], marker="square", size=10, fill_alpha=0
)
points * highlight