Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit bokeh plot pan to defined range

Tags:

python

bokeh

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?

like image 677
thefourtheye Avatar asked Apr 24 '14 18:04

thefourtheye


1 Answers

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")
like image 122
Bryce Guinta Avatar answered Oct 19 '22 19:10

Bryce Guinta