在gmap中使用bokeh中的python添加用于圆的工具提示

时间:2018-07-06 09:37:24

标签: python google-maps bokeh

我的代码是

from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions
import bokeh.plotting as plotting
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)

# 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="Austin",plot_width=screenInfo.winfo_screenwidth()-100, plot_height=screenInfo.winfo_screenheight()-100)

source = ColumnDataSource(
    df

)

p.circle(x="lat", y="lon", size=15,name="Place", fill_color="blue", fill_alpha=0.8, source=source)
plotting.output_file('gmap.html')
show(p)

在这里我需要为圆添加工具提示 我尝试使用

    TOOLTIPS = [
       # ("index", "$index"),
       # ("(x,y)", "($x, $y)"),
        ("Place", "@Place"),
    ]
p = gmap(API_KEY, map_options, tooltip=TOOLTIPS,title="The Hindu",plot_width=screenInfo.winfo_screenwidth()-100, plot_height=screenInfo.winfo_screenheight()-150)

,但是工具提示仅适用于gmap,不适用于gmap。 因此,有没有其他方法可以获取工具提示。

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方法

from bokeh.models import ColumnDataSource, GMapOptions,HoverTool
TOOLTIPS = [
    ("Place", "@Place"),
    ("News","@Title")
]
p.add_tools( HoverTool(tooltips=TOOLTIPS))

我将这些行附加到代码中以获得工具提示