Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple Hover Tools without showing multiple icons in the toolbar?

Tags:

python

bokeh

Following the example here I have added multiple tooltips to a stacked bar chart. I also want to have other tools available in the toolbar above the plot, but when multiple hover tools are created using the process in the example it creates multiple icons in the tool bar, leaving it looking messy like this:

toolbar

Is there a way to add multiple hover tools, and have the toolbar visible with other tools in it, but not duplicate the hover icon?

like image 816
Toby Petty Avatar asked Oct 18 '25 13:10

Toby Petty


1 Answers

Just set the toggleable attribute to False. Check this example, where the hover tool button is hidden:

from bokeh.models import HoverTool, ColumnDataSource, LassoSelectTool, PanTool
from bokeh.plotting import show, figure, curdoc

source = ColumnDataSource(dict(
    x=[1, 2, 3, 4],
    y=[5, 6, 7, 8]
))

p = figure(
    width=400,
    height=400,
    tools='')

p.scatter(
    x='x', y='y', source=source,
    fill_alpha=1.0, line_alpha=1.0, line_color="grey",
    size=6
)

pan = PanTool()
lasso = LassoSelectTool()

tooltips = '''
    <b>X: </b> @{x} <br>
    <b>Y: </b> @{y} <br>
'''
hover = HoverTool(
    toggleable=False,       # add this to all your hover tools
    mode='mouse',
    tooltips=tooltips,
)

tools = (
    pan, lasso, hover
)
p.add_tools(*tools)

curdoc().add_root(p)

Well, and if you want to use only one button then you might use only one hover tool. The model CustomJSHover may be useful for you.

As a workaround you can also update the renderers attribute of each hover pressing some button or custom tool.

like image 116
ChesuCR Avatar answered Oct 21 '25 02:10

ChesuCR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!