[Q] Can widget callback access figure's property?

So, I have the following task:
I have a set of points (pretty large), that I want to plot as a scatterplot. Since the set is large, to make sense of it, I would like to zoom in on a particular point via its index.

I create a TextInput widget, where the index will be input, and during a callback I want to find the corresponding element and set the figure properties

x_range
y_range

``

around this point.

However, I don’t seem to have a good way of doing that, since my attempts are either not doing anything, or completely freezing the browser window…

Here’s my sample code that doesn’t respond to text field changes:

source = ColumnDataSource(

data=dict(

ids = list(range(10)),

x=np.random.rand(10),

y=np.random.rand(10),

)

)

p = figure(plot_width=800, plot_height=800, tools=[‘pan’,‘box_zoom’,‘wheel_zoom’,‘reset’],toolbar_location=‘below’,

x_range=(0,1),y_range=(0,1))

tsneplot.background_fill_color = “grey”

tsneplot.background_fill_alpha = 0.35

p.circle(‘x’,‘y’, size=10, color=‘navy’,source=source)

text_input = TextInput(value=“4”, title=“Enter ID:”)

def callback(source=source,p=p,window=None):

data = source.data

x, y, ids = data[‘x’], data[‘y’], data[‘ids’]

cInd = ids.index(cb_obj.value)

center = [x[cInd],y[cInd]]

p.x_range = Range1d(center[0]-.1,center[0]+.1)

p.y_range = Range1d(center[1]-.1,center[1]+.1)

p.trigger(‘change’)

text_input.callback=CustomJS.from_py_func(callback)

show(gridplot([[widgetbox(text_input)],[p]]))

``

P.S: the toolbar_location seems to be overwritten by gridplot?

Taking the easy bit
of this:

        > P.S: the toolbar_location seems to be overwritten by

gridplot?

gridplot makes its own toolbar. You need to specify
the toolbar_location for the gridplot:

···

http://bokeh.pydata.org/en/latest/docs/reference/layouts.html#bokeh.layouts.gridplot
On 10/12/16 9:36 AM, TonyPlaysGuitar
wrote:

So, I have the following task:
I have a set of points (pretty large), that I want to plot
as a scatterplot. Since the set is large, to make sense of it,
I would like to zoom in on a particular point via its index.

      I create a TextInput widget, where the index will be input,

and during a callback I want to find the corresponding element
and set the figure properties

x_range

                y_range

``

around this point.

      However, I don't seem to have a good way of doing that,

since my attempts are either not doing anything, or completely
freezing the browser window…

      Here's my sample code that doesn't respond to text field

changes:

source = ColumnDataSource(

data=dict(

                ids =

list(range(10)),

x=np.random.rand(10),

y=np.random.rand(10),

)

)

                p = figure(plot_width=800,

plot_height=800,
tools=[‘pan’,‘box_zoom’,‘wheel_zoom’,‘reset’],toolbar_location=‘below’,

x_range=(0,1),y_range=(0,1))

                tsneplot.background_fill_color

= “grey”

                tsneplot.background_fill_alpha

= 0.35

                p.circle('x','y', size=10,

color=‘navy’,source=source)

                text_input =

TextInput(value=“4”, title=“Enter ID:”)

                def

callback(source=source,p=p,window=None):

data = source.data

                x, y, ids = data['x'],

data[‘y’], data[‘ids’]

                cInd =

ids.index(cb_obj.value)

                center =

[x[cInd],y[cInd]]

                p.x_range =

Range1d(center[0]-.1,center[0]+.1)

                p.y_range =

Range1d(center[1]-.1,center[1]+.1)

p.trigger(‘change’)

text_input.callback=CustomJS.from_py_func(callback)

show(gridplot([[widgetbox(text_input)],[p]]))

``

      P.S: the toolbar_location seems to be overwritten by gridplot?

  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/bc8aa9ae-8eb5-4b0c-be7e-4a5270d5e4c4%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/bc8aa9ae-8eb5-4b0c-be7e-4a5270d5e4c4%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

Haha, thanks, Sarah! For some reason I found the GridPlot over here:
http://bokeh.pydata.org/en/latest/docs/reference/models/layouts.html

and thought the description is to come in the next releases…