如何在工具栏中不显示多个图标的情况下添加多个悬停工具? [英] How to add multiple Hover Tools without showing multiple icons in the toolbar?
问题描述
以下示例
是否可以添加多个悬停工具,并使工具栏与其他工具一起可见,但不能复制悬停图标?
只需将 toggleable
属性设置为 False
.请检查隐藏鼠标悬停工具按钮的此示例:
导入HoverTool,ColumnDataSource,LassoSelectTool,PanTool来自bokeh.plotting进口展览,人物,curdoc源= ColumnDataSource(dict(x = [1、2、3、4],y = [5,6,7,8]))p =数字(宽度= 400,高度= 400,工具='')p.scatter(x ='x',y ='y',source = source,fill_alpha = 1.0,line_alpha = 1.0,line_color =灰色",大小= 6)pan = PanTool()套索= LassoSelectTool()工具提示='''< b> X:</b>@ {x}< br>< b> Y:</b>@ {y}< br>'''悬停= HoverTool(toggleable = False,#将其添加到所有悬停工具中模式='鼠标',工具提示=工具提示,)工具=(锅,套索,悬停)p.add_tools(*工具)curdoc().add_root(p)
好吧,如果您只想使用一个按钮,则可以只使用一个悬停工具.模型 CustomJSHover
可能对您有用.
作为解决方法,您还可以更新每个鼠标悬停的 renderers
属性.
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?
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.
这篇关于如何在工具栏中不显示多个图标的情况下添加多个悬停工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!