Changing XY bounds from outside the plot

I want my users to be able to zoom/pan in specific parts of the plot depending on an event external to the plot.

My “data scientist” scenario:

  • I return a holoviews plot in a jupyter notebook cell
    my_recs = hv.Rectangles([[ 0, 10,
    10, 20],
    [ 40, 50,
    30, 40],
    ]).opts(fill_color= ‘black’,line_width=0)
  • in the next cell I want to do something like:
    without returning the plot in this new cell, just modify the plot in the previous cell

My User scenario (a dashboard served on the LAN): by selecting a number in a widget, the plot will zoom on the rectangle associated with it


  • I am not interested in the streams object “BoundsXY” or anything like that, as it’s doing the opposite of what I need to do: this is a “getter” not a “setter”.

  • Using rectangles is just an example. I’m not interested in editing or creating rectangles or polygons.

  • returning my_recs in a function called within a Panel pane, like my_recs.otps(xlim=(0,20)) is not an option as it is extremely slow, it rebuilds the whole figure. I don’t want that. I want to instanciate my initial figure when starting the app, and just change the X and Y bounds from outside the bokeh plot.

Anybody has an idea?

Thanks :slight_smile:

I tried the following without little success:
Cell 1:

my_recs = hv.Rectangles([[ 0, 10,
10, 20],
[ 40, 50,
30, 40],
]).opts(fill_color= 'black',line_width=0)
pp = hv.renderer('bokeh').get_plot(my_recs)

Cell 2:


Cell 3:

r = pp.handles['x_range']

I had to rerun Cell 2 for it to rerender.

Using pp.refresh() did not have any effect if added in Cell 3. It’s going a bit too deep for me now.

However it is much quicker when returning pp.State into a Panel pane rather than my_recs.otps(XXX)