Hello,
I would like to ask, if it’s possible to create tooltip, using HoverTool, where tooltip field will be 0 index of column in dataframe?
I create pandas Dataframe, which then I send to ColumnDataSource. In my dataframe I have several columns with data, and 2 columns (let’s say it’s called “Mode” and “Date”) which contains value only on [0] index. When I create hover instance and add this to the figure, it obviously doesn’t show values for index different than 0. Obviously I might fill up all rows with this value but this is something I’d like to avoid.
Here’s how my code looks like:
import pandas as pd
from datetime import datetime
from bokeh.models import HoverTool
from bokeh.plotting import figure, ColumnDataSource
from bokeh.resources import CDN
from bokeh.embed import file_html
x = pd.Series([1,2,3,4,5,6], name='x')
y = pd.Series([4,3,5,4,3,2], name='y')
df = pd.concat([x, y], axis=1)
df.loc[df.index[0], 'Date'] = datetime.today()
df.loc[df.index[0], 'Mode'] = 'CC'
df.fillna('', inplace=True)
source = ColumnDataSource(df)
hover = HoverTool(
tooltips=[
("Mode", "@Mode"),
("Date", "@Date{%F}"),
("y", "$y"),
("x", "$x")
],
formatters={'Date': 'datetime'}
)
fig = figure()
fig.add_tools(hover)
fig.scatter(x='x', y='y', source=source, marker='square', size=8)
html = file_html(fig, CDN, "x vs y")
with open('test.html', 'w+') as f:
f.write(html)
Is there any way, that I can set value to specified index of column inside HoverTool?