平移工具和车轮缩放后散景情节重建后无法正常工作

时间:2018-04-13 05:19:19

标签: python-3.x data-visualization bokeh

我使用散景进行交互式数据可视化。我需要在下拉回调中重新创建散景图。我能够在回调中重新创建一个绘图,但工具栏在重新创建的绘图中不起作用。我正在使用以下代码。

fig=''
select=Select(title="Select")
def create_figure(attribute='Title'):
    global fig;
    fig=figure(x_axis_type='datetime',plot_width=1000,plot_height=600,tools=['pan','crosshair','wheel_zoom'])

def select_onchange(attr, old, new):
    global fig
    attribute=select.value
    create_figure(attribute)
    lay.children[2]=fig

create_figure()
lay = layout([[count_of_server],[widgetbox(select)],[fig],[widgetbox(button)]])
curdoc().add_root(lay)

我使用的是散景0.12.14

1 个答案:

答案 0 :(得分:0)

以下是代码:

from bokeh.layouts import layout, widgetbox

def app3(doc):
    fig=None
    select=Select(title="Select", options=["A", "B"], value="A")
    def create_figure(attribute='Title'):
        nonlocal fig
        fig=figure(x_axis_type='datetime',plot_width=400,plot_height=200,
                   tools=['pan','crosshair','wheel_zoom'], title=attribute)
        fig.circle(np.random.randn(100), np.random.randn(100))

    def select_onchange(attr, old, new):
        nonlocal fig
        attribute=select.value
        create_figure(attribute)
        lay.children[1].children[0]=fig

    select.on_change("value", select_onchange)

    create_figure()
    lay = layout([[widgetbox(select)],[fig]])
    doc.add_root(lay)

show(app3)