python - Bokeh Select 小部件不更新绘图字形
问题描述
我正在编写 Bokeh 应用程序并尝试实现选择小部件。在我将整个情节与字形等放在一个函数中并将此函数用作我的选择小部件的回调函数之前,一切正常。但表现相当糟糕。因此,我尝试在函数之外制作绘图,然后分别制作回调函数。现在选择小部件不再正常工作。启动应用程序时我没有收到任何错误(我使用 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
)
同样的方式它在一个主要功能中工作良好以创建情节。
有任何想法吗?
问候
解决方案
推荐阅读
- android - React Native - gradle,清单合并错误
- c# - 数据库提供者是否分析和“编译”表达式树?
- c# - 有没有办法从消费项目配置源生成器?
- r - 为速度图添加图例 - 表示值的键字形长度
- message - AnyLogic 消息传递
- amazon-cognito - AWS Cognito 自定义消息触发器 - 阻止消息发送
- spring-boot - 如何使用授权码授予类型通过 Postman 获取访问令牌
- typescript - 如何在打字稿中映射导入
- c# - 使用 PRISM 处理缺失的服务
- python - 如何使用 Python(NLP 或其他)从大量文本中提取自定义数据库长名称?