Custom HoverTool

I am trying to use a custom HoverTool with datashader with the following code :

hover = HoverTool(tooltips=[("Wind speed", "@Wind_Speed")])
rasterize(mesh, precompute=True, aggregator=dsh.mean("Wind_Speed"),
            dynamic=False, x_range=x_range, y_range=y_range,height=height, width=width).opts(cmap=highCmap, colorbar=True, tools=[hover]) 

I tried to remove the aggregator but it doesn’t work too.

When I hover I’ve got
“Wind speed: ???”

I just want to know if it should be possible to use a custom HoverTool or if I’m doing it wrongly

It should definitely be possible, could you double check if the dimension on the returned aggregate actually matches the name on the input:

agg = rasterize(mesh, precompute=True, aggregator=dsh.mean("Wind_Speed"),
            dynamic=False, x_range=x_range, y_range=y_range,height=height, width=width)
print(agg)

The name of the value dimension should then be what you can refer to from the HoverTool spec. I’d also try to specify it like this "@{Wind_Speed}". If that doesn’t help the output of print(mesh) would help me debug it.

1 Like

Thanks for your help

I forgot to mention that when I used the default “hover” by specifying .opts(cmap=highCmap, colorbar=True, tools=["hover"]) the tooltip worked, I have 3 variables shown : “Latitude (degrees_north)”, “Longitude (degrees_east)”, and “Wind_Speed”.

I tried with
hover = HoverTool(tooltips=[("A", "@{Wind_Speed}")])
but it still doesn’t work

agg = rasterize(mesh, precompute=True, aggregator=dsh.mean("Wind_Speed"),
            dynamic=False, x_range=x_range, y_range=y_range,height=height, width=width).opts(cmap=highCmap, colorbar=True, tools=[hover])
print(agg)
:Image   [owiLon,owiLat]   (Wind_Speed)
print(mesh)
:QuadMesh   [owiLon,owiLat]   (Wind_Speed)

I am available if more info is needed

Sorry, totally forgot that image uses the “image” as the CDS key, so try:

hover = HoverTool(tooltips=[("A", "@image")])

In future it would be nice if the code would check the tool for validity and provide helpful error messages.

1 Like

Thanks ! This is working ! I never would have guessed.

I also managed to retrieve the longitude and latitude using
hover = HoverTool(tooltips=[("Longitude": "@x"), ("Latitude": "@y"), ("A", "@image")])