【问题标题】:Is there a way to overlay figures or to get figure handles in bokeh, python有没有办法在散景、python 中叠加图形或获取图形句柄
【发布时间】:2016-10-13 15:18:55
【问题描述】:

我用散景和 python 创建了两个并排绘制的图形,然后我创建了另外两个图形。这些现在绘制在前两个下方。我想要的是用新的替换前两个。有没有办法清除旧的并用新的覆盖它们,或者至少得到它们的句柄?

这里是一个简单的例子

# test.py

from bokeh.layouts import Row
from bokeh.layouts import column
from bokeh.plotting import figure, curdoc

# new plots
s1 = figure(title="my data 1", x_axis_label='x', y_axis_label='y')
s2 = figure(title="my data 2", x_axis_label='x', y_axis_label='y')

# my data
x  = [1, 2, 3, 4, 5]
y1 = [1, 2, 3, 4, 5]
y2 = [3, 5, 7, 9, 11]

# plot lines
s1.line(x, y1, legend="data1", line_width=2)
s2.line(x, y2, legend="data2", line_width=3)
p = Row(s1, s2)

curdoc().add_root(column(p))
print "plot 1 done"

# plot lines again
s1 = figure(title="my data 1", x_axis_label='x', y_axis_label='y')
s2 = figure(title="my data 2", x_axis_label='x', y_axis_label='y')
s1.line(x, y1, legend="data1", line_width=2)
s2.line(x, y2, legend="data2", line_width=3)
p = Row(s1, s2)
curdoc().add_root(column(p))
print "plot 2 done"

【问题讨论】:

    标签: python bokeh figure


    【解决方案1】:

    我找到了答案。对于这个简单的示例,需要添加

    curdoc().clear()
    

    在第二个curdoc().add_root(column(p))之前

    如果您想在保持按钮或其他功能处于活动状态的同时执行此操作(因为 clear 会删除所有内容),这里有一个如何处理它的示例:

    Dynamically add/remove plot using 'bokeh serve' (bokeh 0.12.0)

    【讨论】:

      猜你喜欢
      • 2014-10-31
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多