如何更改绘图工具栏中某些工具按钮工具提示的内容?
How to change the content of some tool button tooltip in a plot toolbar?
我目前在我的绘图中有两个用于两种不同形状的 HoverTools,在工具面板中,无法区分摊位形状的 HoverTool。
有什么方法可以将工具名称从 "Hover" 更改为其他名称?
另一个选项是从工具面板中隐藏 booth 工具,这可能吗?
plot = figure(tools='pan,wheel_zoom,save', active_scroll = "wheel_zoom", x_axis_location=None, y_axis_location=None, output_backend="webgl", plot_width=1200, plot_height= 600, match_aspect=True )
plot.add_tools(HoverTool(renderers=[shape1], tooltips=[('title1',"text1")]))
plot.add_tools(HoverTool(renderers=[shape2], tooltips=[('title2',"text2")]))
您可以像这样明确命名工具:
tools=['pan', 'box_zoom', 'wheel_zoom', 'crosshair', 'reset', 'save']
plot = figure(tools=tools, active_scroll = "wheel_zoom", x_axis_location=None, y_axis_location=None, output_backend="webgl", plot_width=1200, plot_height= 600, match_aspect=True )
shape1 = plot.line([0,1],[2,3])
shape2 = plot.line([4,5],[6,7])
h1 = HoverTool(renderers=[shape1], tooltips=[('title1',"text1")])
h2 = HoverTool(renderers=[shape2], tooltips=[('title2',"text2")])
plot.add_tools(h1, h2)
另一个注意事项 - 如果您将 h1 和 h2 放在您声明工具的初始列表中,您将收到一条警告,指出重复的悬停工具。不过,我还没有看到此警告会导致问题。
关于你的第二个问题
An other option is to hide booth tools from the Tool Panel, is it possible?
我已经回答过类似的问题:
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)
我目前在我的绘图中有两个用于两种不同形状的 HoverTools,在工具面板中,无法区分摊位形状的 HoverTool。
有什么方法可以将工具名称从 "Hover" 更改为其他名称?
另一个选项是从工具面板中隐藏 booth 工具,这可能吗?
plot = figure(tools='pan,wheel_zoom,save', active_scroll = "wheel_zoom", x_axis_location=None, y_axis_location=None, output_backend="webgl", plot_width=1200, plot_height= 600, match_aspect=True )
plot.add_tools(HoverTool(renderers=[shape1], tooltips=[('title1',"text1")]))
plot.add_tools(HoverTool(renderers=[shape2], tooltips=[('title2',"text2")]))
您可以像这样明确命名工具:
tools=['pan', 'box_zoom', 'wheel_zoom', 'crosshair', 'reset', 'save']
plot = figure(tools=tools, active_scroll = "wheel_zoom", x_axis_location=None, y_axis_location=None, output_backend="webgl", plot_width=1200, plot_height= 600, match_aspect=True )
shape1 = plot.line([0,1],[2,3])
shape2 = plot.line([4,5],[6,7])
h1 = HoverTool(renderers=[shape1], tooltips=[('title1',"text1")])
h2 = HoverTool(renderers=[shape2], tooltips=[('title2',"text2")])
plot.add_tools(h1, h2)
另一个注意事项 - 如果您将 h1 和 h2 放在您声明工具的初始列表中,您将收到一条警告,指出重复的悬停工具。不过,我还没有看到此警告会导致问题。
关于你的第二个问题
An other option is to hide booth tools from the Tool Panel, is it possible?
我已经回答过类似的问题
Just set the
toggleable
attribute toFalse
. 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)