enabling the box zoom tool for bokeh.mpl.to_bokeh()

How do you enable the box zoom tool for bokeh.mpl.to_bokeh()? It’s not enabled by default.

Hi,

···

On Mon, Dec 15, 2014 at 7:37 PM, Jason Sachs [email protected] wrote:

How do you enable the box zoom tool for bokeh.mpl.to_bokeh()? It’s not enabled by default.

It looks like it’s currently not possible to directly alter the generated Plot instance. However, you can use the following hack:

(…)

bokeh.mpl.to_bokeh()

from bokeh.plotting import curdoc, show

from bokeh.models import BoxZoomPlot

p = curdoc().curplot()

p.tools = p.tools + [BoxZoomTool(plot=p)] # append() won’t work here

show()

Alternatively you can temporarily modify to_bokeh() to return the figure instead of showing it, e.g.:

p = to_bokeh2()

p.tools = (…)

show§

I think this is how to_bokeh() will work in 0.7.1+.

Mateusz

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5a6168a5-ca8a-47e5-a700-61568d7b0bbd%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I can’t seem to add a BoxZoomTool even if I go in and tinker with things:

import matplotlib.pyplot as plt

import numpy as np

import bokeh.mpl

import bokeh.plotting

import bokeh.objects

class BokehPlotWrapper(object):

adapted from bokeh.mpl.to_bokeh

def init(self, fig=None):

if fig is None:

fig = plt.gcf()

self.fig = fig

def render(self):

bokeh.plotting.output_notebook()

doc = bokeh.plotting.curdoc()

self.renderer = bokeh.mpl.BokehRenderer(pd_obj=False, xkcd=False)

exporter = bokeh.mplexporter.exporter.Exporter(self.renderer)

exporter.run(self.fig)

doc._current_plot = self.renderer.fig # TODO (bev) do not rely on private attrs

doc.add(self.renderer.fig)

p = doc.curplot()

p.tools = p.tools + [bokeh.objects.BoxZoomTool(plot=p)]

def show(self):

bokeh.plotting.show(self.renderer.fig)

t = np.arange(0,4.0,0.0001)

plt.subplot(2,1,1)

plt.plot(t,t**2)

plt.subplot(2,1,2)

plt.plot(t,1-t)

bpw=BokehPlotWrapper(plt.gcf())

bpw.render()

bpw.show()

The toolbar doesn’t change at all, and if I print p.tools it just shows the BoxZoomTool and none of the tools that are actually there already.

···

On Monday, December 15, 2014 12:29:39 PM UTC-7, mateusz.paprocki wrote:

Hi,

On Mon, Dec 15, 2014 at 7:37 PM, Jason Sachs [email protected] wrote:

How do you enable the box zoom tool for bokeh.mpl.to_bokeh()? It’s not enabled by default.

It looks like it’s currently not possible to directly alter the generated Plot instance. However, you can use the following hack:

(…)

bokeh.mpl.to_bokeh()

from bokeh.plotting import curdoc, show

from bokeh.models import BoxZoomPlot

p = curdoc().curplot()

p.tools = p.tools + [BoxZoomTool(plot=p)] # append() won’t work here

show()

Alternatively you can temporarily modify to_bokeh() to return the figure instead of showing it, e.g.:

p = to_bokeh2()

p.tools = (…)

show§

I think this is how to_bokeh() will work in 0.7.1+.

Mateusz

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5a6168a5-ca8a-47e5-a700-61568d7b0bbd%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

The problem here is that you are passing a figure containing subplots… if you try your pasted solution with just one figure it works as expected…
I tried adding the tool to the resulting grid plot and it is not working for me neither… I have to look deeper to see the problem.

In any case, any further development on this will be tracked on these two issues: https://github.com/bokeh/bokeh/issues/1554 and https://github.com/bokeh/bokeh/issues/1557

Cheers.

Damian

···

On Monday, December 15, 2014 5:06:33 PM UTC-3, Jason Sachs wrote:

I can’t seem to add a BoxZoomTool even if I go in and tinker with things:

import matplotlib.pyplot as plt

import numpy as np

import bokeh.mpl

import bokeh.plotting

import bokeh.objects

class BokehPlotWrapper(object):

adapted from bokeh.mpl.to_bokeh

def init(self, fig=None):

if fig is None:

fig = plt.gcf()

self.fig = fig

def render(self):

bokeh.plotting.output_notebook()

doc = bokeh.plotting.curdoc()

self.renderer = bokeh.mpl.BokehRenderer(pd_obj=False, xkcd=False)

exporter = bokeh.mplexporter.exporter.Exporter(self.renderer)

exporter.run(self.fig)

doc._current_plot = self.renderer.fig # TODO (bev) do not rely on private attrs

doc.add(self.renderer.fig)

p = doc.curplot()

p.tools = p.tools + [bokeh.objects.BoxZoomTool(plot=p)]

def show(self):

bokeh.plotting.show(self.renderer.fig)

t = np.arange(0,4.0,0.0001)

plt.subplot(2,1,1)

plt.plot(t,t**2)

plt.subplot(2,1,2)

plt.plot(t,1-t)

bpw=BokehPlotWrapper(plt.gcf())

bpw.render()

bpw.show()

The toolbar doesn’t change at all, and if I print p.tools it just shows the BoxZoomTool and none of the tools that are actually there already.

On Monday, December 15, 2014 12:29:39 PM UTC-7, mateusz.paprocki wrote:

Hi,

On Mon, Dec 15, 2014 at 7:37 PM, Jason Sachs [email protected] wrote:

How do you enable the box zoom tool for bokeh.mpl.to_bokeh()? It’s not enabled by default.

It looks like it’s currently not possible to directly alter the generated Plot instance. However, you can use the following hack:

(…)

bokeh.mpl.to_bokeh()

from bokeh.plotting import curdoc, show

from bokeh.models import BoxZoomPlot

p = curdoc().curplot()

p.tools = p.tools + [BoxZoomTool(plot=p)] # append() won’t work here

show()

Alternatively you can temporarily modify to_bokeh() to return the figure instead of showing it, e.g.:

p = to_bokeh2()

p.tools = (…)

show§

I think this is how to_bokeh() will work in 0.7.1+.

Mateusz

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5a6168a5-ca8a-47e5-a700-61568d7b0bbd%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.