bokeh overlay multiple plot objects in a GridPlot

五迷三道 提交于 2019-11-30 17:46:08

问题


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()

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)

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)

回答1:


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.




回答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)


来源:https://stackoverflow.com/questions/26912632/bokeh-overlay-multiple-plot-objects-in-a-gridplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!