Limit bokeh plot pan to defined range

北城以北 提交于 2019-12-05 01:15:53

问题


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?


回答1:


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")


来源:https://stackoverflow.com/questions/23277066/limit-bokeh-plot-pan-to-defined-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!