Is there a way to overlay figures or to get figure handles in bokeh, python
<p>I created two figures with bokeh and python wich are plotted side by side, then  I created another two figures. These are now plotted underneath the first two. What I want is to replace the first two with the new ones. Is there a way to clear the old ones and overlay them with the new ones or at least to get their handles?</p>

<p>Here a simple example</p>

<pre><code># 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"
</code></pre>

<p><a href="https://i.stack.imgur.com/6p3ol.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/6p3ol.jpg" alt="output"></a></p>

<p>I found the answer. For this simple example one needs to add</p>

<pre><code>curdoc().clear()
</code></pre>

<p>before the second <code>curdoc().add_root(column(p))</code></p>

<p>If you want to do it while keeping buttons or other features alive (because clear deletes everything) here is an example how to deal with it:</p>

<p><a href="http://stackoverflow.com/questions/38548442/dynamically-add-remove-plot-using-bokeh-serve-bokeh-0-12-0">Dynamically add/remove plot using &#39;bokeh serve&#39; (bokeh 0.12.0)</a></p>

python bokeh figure