thefourtheye
thefourtheye

Reputation: 607

Limit bokeh plot pan to defined range

I was wondering if it were possible to limit the range of the "pan" tool for bokeh generated plots? For example, say I had this simple plot:

from bokeh.plotting import output_file, rect, show
output_file('test.html')
rect([10,20,30], [10,20,30], width=[1,2,3], color=['red','blue','green'], height=5, plot_width=400, plot_height=400, tools = "ypan,box_zoom,reset")
show()

The ypan tool works great, but I could keep panning until my graph disappears. Is there any way I can constrain the pan?

Upvotes: 6

Views: 4539

Answers (1)

Bryce Guinta
Bryce Guinta

Reputation: 3712

The pan/zoom limit feature has been added after this question was first posed.

You can feed the y_range or x_range keyword arguments on a bokeh model a Range1d object with the keyword argument bounds set to a tuple to limit the pan boundaries.

from bokeh.plotting import figure
from bokeh.models import Range1d

fig = figure(y_range=Range1d(bounds=(0, 1)),
             x_range=Range1d(bounds=(0, 1)))

Note that the Range1d's first two positional arguments are for setting the default view-port for an axis, and the bounds is independent of those arguments.


If you want your bounds to be limited by the range values, then you can pass bounds auto:

Range1d(0, 1, bounds="auto")

Upvotes: 10

Related Questions