Python 鼠标悬停在Bokeh图形上时显示的工具提示也应显示在工具提示本身上
我编写了一些python代码,用bokeh在地图上显示点。但现在,当鼠标悬停在点上时,工具提示上会显示一些超链接。但由于这是工具提示,我无法单击超链接导航到其他页面。有没有这样做的机会Python 鼠标悬停在Bokeh图形上时显示的工具提示也应显示在工具提示本身上,python,bokeh,Python,Bokeh,我编写了一些python代码,用bokeh在地图上显示点。但现在,当鼠标悬停在点上时,工具提示上会显示一些超链接。但由于这是工具提示,我无法单击超链接导航到其他页面。有没有这样做的机会 from bokeh.io import output_file, show from bokeh.models import ColumnDataSource, GMapOptions,HoverTool,CustomJS import bokeh.plotting as plotting from bokeh
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions,HoverTool,CustomJS
import bokeh.plotting as plotting
from bokeh import events
from bokeh.plotting import gmap
import tkinter as tk
screenInfo=tk.Tk()
map_options = GMapOptions(lat=26.366314, lng= 77.016513, map_type="roadmap", zoom=5)
source = ColumnDataSource(df)
TOOLTIPS = """
<div id="Tooltip">
<div>
<span style="font-size: 17px; font-weight: bold;">@Place</span>
</div>
<div>
<span style="font-size: 15px; color: #966;">@Title<a href="@Link">Click here for more details</a></span>
</div>
</div>
"""
HoverCallback=CustomJS(code="""
""")
# For GMaps to function, Google requires you obtain and enable an API key:
#
# https://developers.google.com/maps/documentation/javascript/get-api-key
#
# Replace the value below with your personal API key:
p = gmap(API_key, map_options, title="The Hindu",plot_width=screenInfo.winfo_screenwidth()-100, plot_height=screenInfo.winfo_screenheight()-150)
p.circle(x="lat", y="lon", size=15,fill_color="blue",fill_alpha=0.8, source=source)
p.add_tools( HoverTool(tooltips=TOOLTIPS,callback=HoverCallback))
plotting.output_file('gmap.html')
show(p)
从bokeh.io导入输出文件,显示
从bokeh.models导入ColumnDataSource、GMapOptions、HoverTool、CustomJS
导入bokeh.plotting作为绘图
从bokeh导入事件
从bokeh.com导入gmap
将tkinter作为tk导入
screenInfo=tk.tk()
地图选项=GMapOptions(纬度=26.366314,液化天然气=77.016513,地图类型=“路线图”,缩放=5)
source=ColumnDataSource(df)
工具提示=“”
@放置
@头衔
"""
HoverCallback=CustomJS(代码=“”)
""")
#为了让GMAP发挥作用,谷歌要求您获取并启用API密钥:
#
# https://developers.google.com/maps/documentation/javascript/get-api-key
#
#用您的个人API密钥替换以下值:
p=gmap(API_键,地图选项,title=“印度教”,绘图宽度=screenInfo.winfo_screenwidth()-100,绘图高度=screenInfo.winfo_screenheight()-150)
p、 圆(x=“lat”,y=“lon”,尺寸=15,填充颜色=blue,填充阿尔法=0.8,源=源)
p、 添加工具(HoverTool(工具提示=工具提示,回调=HoverCallback))
plotting.output_文件('gmap.html')
表演(p)
这是data Frame fromat中df中的数据,您将永远无法单击工具提示本身,因为工具提示始终位于鼠标旁边,而不是鼠标下方。您最好的选择是使用
OpenURL
回调配置TapTool
,以便在单击图示符时打开相同的URL。下面是Bokeh0.13.0
的完整示例:
from bokeh.models import OpenURL, TapTool
from bokeh.plotting import figure, show
url = "http://www.colors.commutercreative.com/@color/"
tooltips = 'Click the circle to go to:<br /><a href="{url}">{url}</a>'.format(url=url)
p = figure(tooltips=tooltips) # "easy" tooltips requires Bokeh >= 0.13.0
data = dict(x=[1, 2, 3], y=[2, 6, 4], color=['firebrick', 'navy', 'olive'])
r = p.circle('x', 'y', color='color', size=25, source=data)
# these lines prevent greying out untapped circles, remove them
# to have default selection/non-selection appearance
r.selection_glyph = None
r.nonselection_glyph = None
tap = TapTool(callback=OpenURL(url=url))
p.add_tools(tap)
show(p)
从bokeh.models导入OpenURL,点击工具
从bokeh.plotting导入图形,显示
url=”http://www.colors.commutercreative.com/@颜色/”
工具提示='单击要转到的圆圈:
'。格式(url=url)
p=图形(工具提示=工具提示)#“简单”工具提示要求Bokeh>=0.13.0
数据=dict(x=[1,2,3],y=[2,6,4],颜色=['firebrick','navy','olive'])
r=p.circle('x','y',color='color',size=25,source=data)
#这些线可以防止未绘制的圆变灰,请删除它们
#具有默认选择/非选择外观的步骤
r、 选择符号=无
r、 非选择符号=无
点击=点击工具(回调=打开url(url=url))
p、 添加工具(点击)
表演(p)
你能把你到目前为止所做工作的代码张贴出来吗?当然可以。我已经做了。请检查codeTap工具将是一个真正的最佳解决方案,但我将有几个单一点的网址。在这种情况下,这将不会被使用,您应该事先明确地声明该需求。我不相信有任何内置的东西可以为该用例提供解决方案。您可以编写自己的自定义扩展来满足您的需求。这是一个不同的问题,所以应该放在一个新的不同的so帖子中。