散景 - 清除 'figure' 的先前条目(绘图)
Bokeh - clear previous entries of 'figure' (plot)
我正在尝试根据用户选择更新我的情节(我希望每次选择更改时刷新整个 figure/plot),但我看到情节被添加到之前创建的在同一地块区域绘制地块。我在这里搜索类似的帖子,但找不到我正在寻找的答案。我遇到了 this 但我无法让它工作。
如果用户选择 3 次,绘图会显示所有这 3 次选择的数据,而不是每次都用新数据覆盖。我觉得很奇怪,默认行为是不刷新。非常感谢对此问题的任何帮助!
这是我的代码:
button = Button(label='Plot')
output = Paragraph()
cluster_slider = Slider(start=2,end=10,step=1,title='Clusters',value=3)
select1 = Select(title='Parameter1',value='Value', options=['Age','Value','Industry'])
select2 = Select(title='Parameter1',value='Age', options=['Age','Value','Industry'])
p = figure(plot_width=400, plot_height=400)
def plot_clusters():
<processing logic>
p.circle(dfinput[sel1], dfinput[sel2], size=2, color=colors, alpha=0.5)
button.on_click(plot_clusters)
lay_out = layout([[cluster_slider,[select1,select2],button],[output]])
curdoc().add_root(lay_out)
curdoc().add_root(p)
终于解决了。将其张贴在这里是为了他人的利益:
诀窍是定义一个包含一行 2 项的布局,并在 click/change.
时更新第二项
from bokeh.layouts import layout,row
p = figure(plot_width=400, plot_height=400)
def plot_clusters():
<processing logic>
p=figure(plot_width=400, plot_height=400)
p.circle(x,y, size=2, color=colors, alpha=0.5)
lay_out.children[1]=p # set the second element of layout to the new figure
button.on_click(plot_clusters)
lay_out = row(controls,p) #controls can be select, slider etc.
curdoc().add_root(lay_out)
我正在尝试根据用户选择更新我的情节(我希望每次选择更改时刷新整个 figure/plot),但我看到情节被添加到之前创建的在同一地块区域绘制地块。我在这里搜索类似的帖子,但找不到我正在寻找的答案。我遇到了 this 但我无法让它工作。
如果用户选择 3 次,绘图会显示所有这 3 次选择的数据,而不是每次都用新数据覆盖。我觉得很奇怪,默认行为是不刷新。非常感谢对此问题的任何帮助!
这是我的代码:
button = Button(label='Plot')
output = Paragraph()
cluster_slider = Slider(start=2,end=10,step=1,title='Clusters',value=3)
select1 = Select(title='Parameter1',value='Value', options=['Age','Value','Industry'])
select2 = Select(title='Parameter1',value='Age', options=['Age','Value','Industry'])
p = figure(plot_width=400, plot_height=400)
def plot_clusters():
<processing logic>
p.circle(dfinput[sel1], dfinput[sel2], size=2, color=colors, alpha=0.5)
button.on_click(plot_clusters)
lay_out = layout([[cluster_slider,[select1,select2],button],[output]])
curdoc().add_root(lay_out)
curdoc().add_root(p)
终于解决了。将其张贴在这里是为了他人的利益: 诀窍是定义一个包含一行 2 项的布局,并在 click/change.
时更新第二项from bokeh.layouts import layout,row
p = figure(plot_width=400, plot_height=400)
def plot_clusters():
<processing logic>
p=figure(plot_width=400, plot_height=400)
p.circle(x,y, size=2, color=colors, alpha=0.5)
lay_out.children[1]=p # set the second element of layout to the new figure
button.on_click(plot_clusters)
lay_out = row(controls,p) #controls can be select, slider etc.
curdoc().add_root(lay_out)