Hi,
I am trying to add extra variables (from a Xarray Dataset) in the hover of a image
or contourf
plot.
Here is a reproducible example:
import xarray as xr
import hvplot.xarray # noqa
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
air_ds = xr.tutorial.open_dataset('air_temperature').load()
meanairbyyear = air_ds.air.groupby('time.year').mean()
stdairbyyear = air_ds.air.groupby('time.year').std()
meanair2d = xr.Dataset(
{
"y2013": (["lat", "lon"], meanairbyyear[0,:,:]),
"y2014": (["lat", "lon"], meanairbyyear[1,:,:]),
},
coords={
"lon": ("lon", meanairbyyear.lon),
"lat": ("lat", meanairbyyear.lat),
},
)
meanair2d
pl=meanair2d.hvplot.image(z='y2013',width=400)
from bokeh.models import HoverTool
MyHover = HoverTool(
tooltips=[
( 'x', '$x'),
( 'y', '$y'),
( 'Year 2013', '@image{%3.0f} degC'),
( 'Year 2014', '@y2014{%3.0f} degC'),
],
formatters={
'$x' : 'numeral',
'$y' : 'numeral',
'@image' : 'printf',
'@y2014' : 'printf',
},
point_policy="follow_mouse"
)
pl.opts(tools = [MyHover])
I would like to display the value of y2014 in addition to the one from y2013. With the code above I have ???
displayed for the variable y2014.
Any idea how to tackle this?
I have the same problem when plotting with contourf
:
pl=meanair2d.hvplot.contourf(z='y2013',width=400)
from bokeh.models import HoverTool
MyHover2 = HoverTool(
tooltips=[
( 'x', '$x'),
( 'y', '$y'),
( 'Year 2013', '@y2013{%3.0f} degC'),
( 'Year 2014', '@y2014{%3.0f} degC'),
],
formatters={
'$x' : 'numeral',
'$y' : 'numeral',
'@y2013' : 'printf',
'@y2014' : 'printf',
},
point_policy="follow_mouse"
)
pl.opts(tools = [MyHover2])
Thank you!