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?