问题
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:
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?
回答1:
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.
来源:https://stackoverflow.com/questions/53216167/how-to-add-multiple-hover-tools-without-showing-multiple-icons-in-the-toolbar