简体   繁体   English

如何自定义散景中的悬停

[英]How to customize hover in bokeh

[enter image description here][1]I am using bokeh to show the babynames info on the USA map. [在此处输入图像描述][1]我正在使用散景在美国地图上显示婴儿姓名信息。 Now I draw the map, I want to use hover to show babynames.现在我绘制地图,我想使用悬停来显示宝宝的名字。 But I cannot change the connect in hover.但我无法在悬停时更改连接。 How can I do?我能怎么做? my file name is df_latlon我的文件名是 df_latlon

Here are my code:这是我的代码:

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 This is a screenshot of my file https://i.stack.imgur.com/ZIMT8.png这是我的文件截图

您必须实际将悬停工具添加到绘图中才能产生任何效果:

p.add_tools(hover)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM