Python:如何更新bokeh补丁字段?
我正在使用Python:如何更新bokeh补丁字段?,python,bokeh,Python,Bokeh,我正在使用bokeh,我想更新补丁的字段值 首先,我将一个geodataframegdf转换为一个GeoJSONDataSource from bokeh.models import LogColorMapper from bokeh.palettes import Viridis256 as palette from bokeh.models.glyphs import Patch from bokeh.models import GeoJSONDataSource, Select geo_
bokeh
,我想更新补丁的字段
值
首先,我将一个geodataframegdf
转换为一个GeoJSONDataSource
from bokeh.models import LogColorMapper
from bokeh.palettes import Viridis256 as palette
from bokeh.models.glyphs import Patch
from bokeh.models import GeoJSONDataSource, Select
geo_gdf = GeoJSONDataSource(geojson=gdf.to_json())
w = 200
h = 200
field = 'col1' ## choose col1 as field to plot
vmin = min(gdf[field])
vmax = max(gdf[field])
## create plot
p = figure(plot_width=w,plot_height=h)
color_mapper = LogColorMapper(palette=palette, low=vmin, high=vmax)
## Patches definition
grid=p.patches('xs', 'ys', source = geo_source2, name="grid",
fill_color={'field': field, 'transform': color_mapper},
fill_alpha=0.5, line_color="gray", line_width=2)
我想通过选择一个选项来更改字段
select = Select(title="Options", options = ['Col1', 'Col2'], value = 'Col1')
def update_plot(attrname, old, new):
option = select.value
if option == 'Col1':
p.field = 'Col1'
if option == 'Col2':
p.field = 'Col2'
select.on_change('value', update_plot)
curdoc().add_root(select)
字段
不是glyph的属性,它是关于如何处理特定属性(例如填充颜色
)的规范。您需要以与设置相同的方式进行更新:
grid.glyph.fill_color = {'field': option, 'transform': color_mapper}