如何自定义bokeh中的悬停

2024-04-29 16:08:37 发布

您现在位置:Python中文网/ 问答频道 /正文

[在此处输入图像描述][1]我正在使用bokeh在美国地图上显示babynames信息。现在我画地图,我想用悬停来显示婴儿。但我无法更改连接悬停。我该怎么办? 我的文件名是dfu latlon

这是我的密码:

from bokeh.models import HoverTool
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.sampledata import us_states
us_states = us_states.data.copy()

state_xs = [us_states[code]["lons"] for code in us_states]
state_ys = [us_states[code]["lats"] for code in us_states]
name=df_latlon["Name"]
T = "pan,wheel_zoom,reset,hover,save"

p = figure(title="Top 1 name of every state form 1910 to 2014", tools=T,
           toolbar_location="left", plot_width=3000, plot_height=1300)

p.patches(state_xs, state_ys, fill_alpha=0.3,
        line_color="blue", line_width=1.5)

x = df_latlon["lon"]
y = df_latlon["lat"]

source = ColumnDataSource(data=dict(
    name=df_latlon["Name"],
    gender=df_latlon["Gender"]
    ))
hover = HoverTool(tooltips=[("Name", "@name"),("Gender","@gender")])


output_file("statenametop1.html")


show(p)

https://i.stack.imgur.com/ZIMT8.png 这是我文件的截图


Tags: namefromimportdfoutput地图bokehcode