I am building an interactive plot tool with Bokeh.
My data is composed by several 2D matrixes of equal dimensions. Each matrix is plotted with the glyph rect, and I use a select model to query different matrixes.
I have managed to set my widgets and callbacks correctly but there seems to be an issue every time I switch matrix, with regards to tooltips text.
I use tooltips text to check the matrix and magnitud of the plotted rectangle. When I update tooltips, it updates the value correctly but does not update the name (Check picks below).
My update function is set like this:
def update(attr,old,new):
#Update colors
top_2D_figure.renderers[0].glyph.update(fill_color=set_color(data,select_pmt.value))
#Update Hovertool
parameter_name = select_pmt.value
tooltips_str = set_str_tooltips(data, parameter_name)
top_2D_figure.tools[0].tooltips = tooltips_str
Where set_str_tooltips
is a fucntion that just checks if the data variable is a number or a string and returns a tuple equivalent to (value,name)
def set_str_tooltips(df, *col):
tt_text = [('cell','@ElName')]
for c in col:
col_name = c
if df[c].apply(isinstance,args = [float]).all():
col_value = '@'+c+'{e.00}'
tt_text.append((col_name,col_value))
else:
col_value = '@'+c
tt_text.append((col_name,col_value))
return tt_text
For debugging purposes I have printed the output of such function and the string tuples seem correct. For the actions performed in the pics below, it does print:
[('cell', '@ElName'), ('MA12', '@MA12')]
[('cell', '@ElName'), ('T', '@T{e.00}')]
So, I do not understand why it updates correctly only the value of the glyph but not the name.
At the moment I have a workaround wich is to delete the hovertools from my figure:
top_2D_figure.tools.pop(-1)
And then re-add my hover tool with the new text. And it works
top_2D_figure.add_tools(HoverTool(tooltips = tooltips_str))
Thanks!