我正在尝试使用bokeh
在特定区域中选择点,并且正在使用函数selectBoundary
,如下所述。建筑物上的选择select
有效,而城市上的选择无效select1
,我也不知道为什么
import geopandas as gpd
from geopandas.tools import sjoin
s = schools.copy() ## schools point (geopandas dataframe)
h = hf.copy() ## hospitals points (geopandas dataframe)
dpt = cities.copy() ## cities (geopandas dataframe)
def selectBoundary(dptSelected):
if dptSelected == 'City1':
dptTmp = dpt[dpt.index==0]
s = sjoin(schools, dpt)
h = sjoin(hf, dpt)
else:
s = schools.copy()
h = hf.copy()
return s,h
def update_plot(attrname, old, new):
s,h = selectBoundary(select1.value)
if select.value == 'Schools':
point0=dict(
x=list(s['x'].values),
y=list(s['y'].values),
)
newSource = point0
if select.value == 'Hospitals':
point1=dict(
x=list(h['x'].values),
y=list(h['y'].values),
)
newSource = point1
source_point.data = newSource
做图
point0=dict(
x=list(s['x'].values),
y=list(s['y'].values),
)
point1=dict(
x=list(h['x'].values),
y=list(h['y'].values),
)
source_point = ColumnDataSource(data = point0)
p = figure(plot_width=800,
tooltips=[("(Long, Lat)", "($x, $y)")])
p.hover.point_policy = "follow_mouse"
p.circle('x', 'y', size=1,
source = source_point,
color="black")
## Selection
select = Select(title="Buildings", options=['Schools', 'Hospitals' ])
## Selection
select1 = Select(title="Departments", options = ['None', 'City1'])
## Controls
controls = widgetbox(select, select1)
select.on_change('value', update_plot)
select1.on_change('value', update_plot)
layout = column(row(controls), p)
curdoc().add_root(layout)