Mutlivariate hvplot.quadmesh with custom hover?

I am creating a hvplot of a multivariate netcdf / xarray datasets and am trying to override the default hover tool such that only variable value is displayed in the hover tool (i.e. no x/y coords).

I have successfully used tooltips=[(“value”,"@image")] when creating a hvplot.image() …(See hypothetical example below) but cannot reproduce the same result using hvplot.quadmesh(). I have attempted using “@z” in the tooltips but always end up with ??? in the hover

import xarray as xr
import hvplot.pandas  # noqa
import hvplot.xarray  # noqa
import cartopy.crs as ccrs
from bokeh import models
import numpy as np
air_ds = xr.tutorial.open_dataset('air_temperature').load()
air_ds['air2'] = air_ds['air'] * 2

# Using hvplot.image() works
#  @image for multivariate hvplot.image()

hover = models.HoverTool(tooltips=[("value", "@image"),
                                  ])
air_ds.hvplot.image(
    x='lon', y='lat', z= list(air_ds.data_vars), projection=ccrs.Orthographic(-90, 30),
    global_extent=True, frame_height=540, cmap='viridis', tools=[hover],
    coastline=True
)

# Quadmesh hover not working
# '@z'  not ok ... gives ???

hover = models.HoverTool(tooltips=[("value", "@z"),
                                  ])
air_ds.hvplot.quadmesh(
    x='lon', y='lat', z= list(air_ds.data_vars), projection=ccrs.Orthographic(-90, 30),
    global_extent=True, frame_height=540, cmap='viridis', tools=[hover],
    coastline=True
)

Any guidance would be great
Cheers

1 Like

I tried to run it but the code breaks. It seems that the last version of hvplot don’t support the assignment of a list of variable to z:
I had to replace z= list(air_ds.data_vars) by z= list(air_ds.data_vars)[0] or z='air' to make the code run.

In your case for quadmesh, I managed to make it run by indicating the name of the variable with @:

# hover = models.HoverTool(tooltips=[("value", "@air"),
                                  ])
air_ds.hvplot.quadmesh(
    x='lon', y='lat', z= list(air_ds.data_vars)[0],tools=[hover],
)

Let me know if you know how to add the additional value air2 on the hover. It is something I would like to know.
I opened an issue about it here: How to add an extra variable to hover on image or contourf plot?

hover_cols may be the solution.

1 Like

Thank you, I tried adding it but I got an error:

DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['y2014']

Interface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html

If I understand it properly it means the option hover_cols is not supported with xarray datasets

In case anyone is looking at this:

1 Like