5

Say I have a class that holds some data and implements a function that returns a bokeh plot

import bokeh.plotting as bk
class Data():
    def plot(self,**kwargs):
        # do something to retrieve data
        return bk.line(**kwargs)

Now I can instantiate multiple of these Data objects like exps and sets and create individual plots. If bk.hold() is set they'll, end up in one figure (which is basically what I want).

bk.output_notebook()
bk.figure()
bk.hold()
exps.scatter(arg1)
sets.plot(arg2)
bk.show()

enter image description here

Now I want aggregate these plots into a GridPlot() I can do it for the non overlayed single plots

bk.figure()
bk.hold(False)
g=bk.GridPlot(children=[[sets.plot(arg3),sets.plot(arg4)]])
bk.show(g)

enter image description here

but I don't know how I can overlay the scatter plots I had earlier as exps.scatter.

Is there any way to get a reference to the currently active figure like:

rows=[]
exps.scatter(arg1)
sets.plot(arg2)
af = bk.get_reference_to_figure()
rows.append(af) # append the active figure to rows list
bg.figure()     # reset figure

gp = bk.GridPlot(children=[rows])
bk.show(gp)

2 Answers 2

6

As of Bokeh 0.7 the plotting.py interface has been changed to be more explicit and hopefully this will make things like this simpler and more clear. The basic change is that figure now returns an object, so you can just directly act on those objects without having to wonder what the "currently active" plot is:

p1 = figure(...)
p1.line(...)
p1.circle(...)

p2 = figure(...)
p2.rect(...)

gp = gridplot([p1, p2])
show(gp)

Almost all the previous code should work for now, but hold, curplot etc. are deprecated (and issue deprecation warnings if you run python with deprecation warnings enabled) and will be removed in a future release.

Sign up to request clarification or add additional context in comments.

Comments

2

Ok apparently bk.curplot() does the trick

exps.scatter(arg1)
sets.plot(arg2)
p1 = bk.curplot()
bg.figure()     # reset figure
exps.scatter(arg3)
sets.plot(arg4)
p2 = bk.curplot()
gp = bk.GridPlot(children=[[p1,p2])
bk.show(gp)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.