我正在对Bokeh应用程序进行编程,并尝试实现select小部件。在使用一个函数使用字形等进行整个绘图并将此函数用作我的选择小部件的回调函数之前,一切正常。但是性能很差。因此,我尝试将绘图放在一个函数之外,然后在回调函数之外单独进行。现在,选择小部件无法正常工作。启动应用程序时没有出现任何错误(我使用Bokeh serve --show main.py方法)。选择窗口小部件应更改y轴的值并同时更新y轴标签。标签已更新,但值未更改。我的代码如下:
sel_yaxis = Select(
title='Select Y Axis',
options=sorted(head_columns.keys()),
value='Demonstrative word'
)
def set_axis(attr, old, new):
# Save value for y-axis from select input widget within the "top" variable
# in the glyph. It will automatically update on changing the select widget within the application.
y_axis = head_columns[sel_yaxis.value]
# Set the label on y-axis so that the glyph displayed and y-axis label match
p.yaxis.axis_label = sel_yaxis.value
c.yaxis.axis_label = sel_yaxis.value
sel_yaxis.on_change('value', set_axis)
p = figure(
title='',
plot_width=1000,
plot_height=700,
x_axis_label='ID',
toolbar_location='above',
tools='pan, box_select, save, undo, redo, xwheel_zoom, reset'
)
c = figure(
title='',
plot_width=1000,
plot_height=700,
x_axis_label='ID',
toolbar_location='above',
tools='pan, box_select, save, undo, redo, xwheel_zoom, reset'
)
# Holds the x-axis ID values for the glyph
id = head_columns['id']
p.yaxis.axis_label = sel_yaxis.value
c.yaxis.axis_label = sel_yaxis.value
# Render glyph into plot
p.vbar(
x=id,
top=y_axis,
source=source,
width=0.8,
line_alpha=0.3,
)
c.scatter(
x=id,
y=y_axis,
source=source
)
以相同的方式在一个主要函数中正常工作以创建绘图。
有什么想法吗?
致谢