我有一些带有一些字形的图形,但只想显示某些字形的工具提示。目前有什么方法可以在Bokeh中完成此操作?散景绘图:仅为某些字形启用工具提示
或者,有没有办法将两个数字打在一起?看起来这样可以让我完成我想要做的事情。
我有一些带有一些字形的图形,但只想显示某些字形的工具提示。目前有什么方法可以在Bokeh中完成此操作?散景绘图:仅为某些字形启用工具提示
或者,有没有办法将两个数字打在一起?看起来这样可以让我完成我想要做的事情。
由于这个页面在谷歌论坛我想出如何可以做到这一点。 Link here
编辑2015年10月20日:看起来像谷歌组链接已经不遗憾的是工作。这是来自Sarah Bird @bokehplot的消息。
编辑2017-01-18:目前这会将多个悬停工具图标添加到工具栏。这可能会导致问题。 github here已经存在一个问题。或者,在下面的答案中尝试@ tterry的解决方案。
从本质上讲,你需要(背景虚化版本0.9.2):当你创建人物
tools
添加hover
例子:
import bokeh.models as bkm
import bokeh.plotting as bkp
source = bkm.ColumnDataSource(data=your_frame)
p = bkp.figure(tools='add the tools you want here, but no hover!')
g1 = bkm.Cross(x='col1', y='col2')
g1_r = p.add_glyph(source_or_glyph=source, glyph=g1)
g1_hover = bkm.HoverTool(renderers=[g1_r],
tooltips=[('x', '@col1'), ('y', '@col2')])
p.add_tools(g1_hover)
# now repeat the above for the next sets of glyphs you want to add.
# for those you don't want tooltips to show when hovering over, just don't
# add hover tool for them!
此外,如果你需要的传奇添加到每个要添加的字形,请尝试使用bokeh.plotting_helpers._update_legend()
方法。 github source如:
_update_legend(plot=p, legend_name='data1', glyph_renderer=g1_r)
图像类型字形和线形字形当前不支持悬停。因此,将这些字形中的一个与支持悬停工具提示的字形结合使用可能是一种解决方法。
参见: http://bokeh.pydata.org/en/latest/docs/user_guide/objects.html#hovertool
Will Zhang's answer会的工作,但你最终会与多个悬停工具。如果这是不可取的,你可以添加渲染到现有的悬停工具:
from bokeh import plotting
from bokeh.models import HoverTool, PanTool, ResetTool, WheelZoomTool
hover_tool = HoverTool(tooltips=[('col', '@x'),('row', '@y')]) # instantiate HoverTool without its renderers
tools = [hover_tool, WheelZoomTool(), PanTool(), ResetTool()] # collect the tools in a list: you can still update hover_tool
plot = plotting.figure(tools=tools)
plot.line(x_range, y_range) # we don't want to put tooltips on the line because they can behave a little strange
scatter = plot.scatter(x_range, y_range) # we assign this renderer to a name...
hover_tool.renderers.append(scatter) # ...so we can add it to hover_tool's renderers.
所以这里的区别:
plotting
接口,这将一个高层次的方式来创建你的字形仍然工作。你需要对你有兴趣在具有悬停工具活跃了,然后设置在悬停工具的names=
属性名称中的字形的name=
属性来命名字形。 (注意fig.line
字形的name=
属性在下面的例子。
hover = HoverTool(mode='vline', line_policy='nearest', names=['ytd_ave'],
tooltips=[
("Week Number", "@WeekNumber"),
("OH for the Week", "@OverHead{0.00}%"),
("OH Average", "@AveOverHead{0.00}%"),
("Non-Controllable Hours", "@NonControllableHours{0.0}"),
("Controllable Hours", "@ControllableHours{0.0}"),
("Total Hours", "@TotalHours{0.0}"),
]
)
fig = Figure(title='Weekly Overhead', plot_width=950, plot_height=400,
x_minor_ticks=2, tools=['pan', 'box_zoom', 'wheel_zoom', 'save',
'reset', hover])
ch = fig.vbar('WeekNumber', top='ControllableHours', name='Over Head',
color='LightCoral', source=sources, width=.5)
nch = fig.vbar('WeekNumber', bottom='ControllableHours', top='TotalOHHours',
name='Non-Controllable Over Head', color='LightGray',
source=sources, width=.5)
bh = fig.vbar('WeekNumber', bottom='TotalOHHours', top='TotalHours',
name='Project Hours', color='LightGreen', source=sources,
width=.5)
ave = fig.line('WeekNumber', 'AveOverHead', source=sources, color='red',
y_range_name='Percent_OH', name='ytd_ave')
只需要注意,如果你这样做,工具提示将不尊重对方的空间,如果你碰巧在同一时间悬停在两个不同的字形上,工具提示将互相重叠。他们尊重彼此的空间吗? – Guillochon 2016-03-26 18:40:27
是的,我也注意到了这一点。明看这个问题,但很想听听somone是否有解决方案。 – WillZ 2016-03-26 21:40:41