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")])

Hi sir,

Do you know how to display another dimension on the hover?

For example:

hover = HoverTool(tooltips=[("Longitude": "@x"), ("Latitude": "@y"), ("Wind speed", "@image") ("Temperature", "@Temperature")])
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]) 

Here I want to show the wind speed and temperature (temperature information is included in the mesh). The above approach does not work. It seems rasterize will ignore the fourth dimension directly.

Do you have any solution to it? I would appreciate it if you let me know.
Thanks!

Welcome to the community @kanglcn

Try to open a new post with your question and update your example to be a minimal, reproducible example (MRE). Which is a complete script that can be copied/pasted and immediately run as-is, with no modifications. This is much more useful than snippets.

1 Like

Thanks for your notification. I made one here: One dimension missing on hover after rasterize point data - Datashader - HoloViz Discourse

2 Likes