首页 > 解决方案 > 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
)

同样的方式它在一个主要功能中工作良好以创建情节。

有任何想法吗?

问候

标签: pythonwidgetbokeh

解决方案


推荐阅读