散景在GridPlot中覆盖多个绘图对象 [英] bokeh overlay multiple plot objects in a GridPlot

查看:122
本文介绍了散景在GridPlot中覆盖多个绘图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个可容纳一些数据并实现返回散景图的函数的类

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)

现在,我可以实例化多个这些数据对象,例如expssets并创建单个图.如果设置了bk.hold(),他们将得到一个数字(基本上就是我想要的).

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

现在,我想将这些图汇总成GridPlot(),我可以对未覆盖的单个图进行处理

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)

但是我不知道如何覆盖我以前作为exps.scatter的散点图.

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)

推荐答案

从Bokeh 0.7开始,plotting.py界面已更改为更加明确,希望这样可以使事情变得更加简单和清晰.基本变化是figure现在返回一个对象,因此您可以直接对那些对象执行操作,而不必怀疑当前活动"图是什么:

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)

几乎所有先前的代码现在都应该可以使用,但是不推荐使用holdcurplot等(如果在启用了弃用警告的情况下运行python,则发出弃用警告),并将在以后的版本中将其删除.

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.

这篇关于散景在GridPlot中覆盖多个绘图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆