Reputation: 847
I am visualising a large dataframe with holoviews/bokeh and want to customise the tooltips. I'll exemplify:
import bokeh
import datashader as ds
import holoviews as hv
from holoviews import opts
from holoviews.operation.datashader import datashade, shade, dynspread, spread, rasterize
hv.extension('bokeh')
Creating mock data:
import numpy as np
import pandas as pd
N = int(10e6)
x_r = (0,100)
y_r = (100,2000)
z_r = (0,10e8)
x = np.random.randint(x_r[0]*1000,x_r[1]*1000,size=(N, 1))
y = np.random.randint(y_r[0]*1000,y_r[1]*1000,size=(N, 1))
z = np.random.randint(z_r[0]*1000,z_r[1]*1000,size=(N, 1))
z2 = np.ones((N,1)).astype(int)
df = pd.DataFrame(np.column_stack([x,y,z,z2]), columns=['x','y','z','z2'])
df[['x','y','z']] = df[['x','y','z']].div(1000, axis=0)
df
And then visualise away:
from matplotlib.cm import get_cmap
palette = get_cmap('viridis')
# palette_inv = palette.reversed()
p=hv.Points(df,['x','y'], ['z','z2'])
P=rasterize(p, aggregator=ds.sum("z2"),x_range=(0,100)).opts(cmap=palette)
P.opts(tools=["hover"]).opts(height=500, width=500,xlim=(0,100),ylim=(100,2000))
This however shows the tooltip for z2
as x_y z2
, and x/y need custom annotations, too so I:
from bokeh.models import HoverTool
hover = HoverTool(tooltips=[
('custom1','$y{0.000}'),('custom2','$x{0.000}'),('custom3','@{x_y z2}{0.0}')
])
hover.point_policy='snap_to_data'
hover.line_policy='none'
P.opts(default_tools = [], tools=[hover,"wheel_zoom","box_zoom","reset"])
But custom3
is displayed as the literal '${x_y z2}{0.0}'
. Using '@{x_y z2}{0.0}'
- shows '???'
; as does '@z2'
.
Just in case the above 'x_y z2'
indicates stacking, tried using '@$z2{0.0}'
- shows no tooltip at all; as does '$z2'
.
I followed the bokeh doc which the respective holoviews docs section references, and now I'm out of things to try. There must be some way to access the value dimensions, since it's shown in the default hover. Did I overlook something?
Upvotes: 1
Views: 447
Reputation: 11
I just ran into the same problem and managed to get it to work by linking 'x_y' and the data item using an '_', so in your example it would be
@{x_y_z2}{0.0}
Give that a try and see if it works, it works in my situation.
Upvotes: 1