3
我正在通過this例如散景教程頁面。我想知道是否可以自定義懸停動作。我想要實現的是在懸浮多邊形上生成黑色加權邊界,以便將其與其他多邊形分開。像this leafletjs示例。我也希望顏色表顯示每種顏色代表的內容。我真的很感謝一些幫助。自定義散景德州失業示例
我正在通過this例如散景教程頁面。我想知道是否可以自定義懸停動作。我想要實現的是在懸浮多邊形上生成黑色加權邊界,以便將其與其他多邊形分開。像this leafletjs示例。我也希望顏色表顯示每種顏色代表的內容。我真的很感謝一些幫助。自定義散景德州失業示例
此答案與您引用的leafletJS示例不完全相同,但它幾乎存在。用戶現在可以隔離懸停的縣。
# # Uncomment the following 3 lines for display in Jupyter notebook.
# from bokeh.io import push_notebook, show, output_notebook
# from bokeh.resources import INLINE
# output_notebook(resources=INLINE)
from bokeh.io import show
from bokeh.models import (
ColumnDataSource,
HoverTool,
LogColorMapper,
CustomJS
)
from bokeh.palettes import Viridis6 as palette
from bokeh.plotting import figure
from bokeh.sampledata.us_counties import data as counties
from bokeh.sampledata.unemployment import data as unemployment
palette.reverse()
counties = {
code: county for code, county in counties.items() if county["state"] == "tx"
}
county_xs = [county["lons"] for county in counties.values()]
county_ys = [county["lats"] for county in counties.values()]
county_names = [county['name'] for county in counties.values()]
county_rates = [unemployment[county_id] for county_id in counties]
color_mapper = LogColorMapper(palette=palette)
source = ColumnDataSource(data=dict(
x=county_xs,
y=county_ys,
name=county_names,
rate=county_rates,
))
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"
p = figure(
title="Texas Unemployment, 2009", tools=TOOLS,
x_axis_location=None, y_axis_location=None
)
p.grid.grid_line_color = None
p.patches('x', 'y', source=source,
fill_color={'field': 'rate', 'transform': color_mapper},
fill_alpha=0.7, line_color="black", line_width=0.5)
hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
("Name", "@name"),
("Unemployment rate)", "@rate%"),
("(Long, Lat)", "($x, $y)"),
]
code = "source.set('selected', cb_data['index']);"
callback = CustomJS(args={'source': source}, code=code)
hover.callback = callback
show(p)
很酷,看起來不錯!謝謝。 – MrPyCharm