如何在 python 全息视图中限制缩放最小和最大范围?
How to restrict zoom min and max ranges in python holoviews?
我正在使用 holoviews 使用以下命令显示 RGB 图片(堆栈 [1] 是我要显示的图像):
pix = hv.RGB(stack[1]).opts(
xaxis=None,
yaxis=None,
tools=['wheel_zoom','pan'],
default_tools=[],
active_tools=['wheel_zoom','pan']
)
它显示正常,但是当我使用滚轮缩放时,我可以缩小到超出图像限制的范围。有没有办法限制我的情节的限制,使其永远不会超过我的 data/image?
的边界
可能有一个选项,但你可以为此使用一个挂钩
import holoviews as hv
hv.extension('bokeh')
import numpy as np
from functools import partial
def bounds_hook(plot, elem, xbounds=None, ybounds=None):
x_range = plot.handles['plot'].x_range
y_range = plot.handles['plot'].y_range
if xbounds is not None:
x_range.bounds = xbounds
else:
x_range.bounds = x_range.start, x_range.end
if ybounds is not None:
y_range.bounds = ybounds
else:
y_range.bounds = y_range.start, y_range.end
(hv.Image(np.random.rand(100,100)).opts(hooks=[bounds_hook]) +
hv.Image(np.random.rand(100,100)).opts(hooks=[partial(bounds_hook, xbounds=(-1, 1), ybounds=(-1,1))], axiswise=True))
def plot_limits(plot, element):
plot.handles['x_range'].min_interval = 100
plot.handles['x_range'].max_interval = 5500000
plot.handles['y_range'].min_interval = 500
plot.handles['y_range'].max_interval = 900000
hv.Image(np.random.rand(100,100)).opts=hooks=[plot_limits]
我正在使用 holoviews 使用以下命令显示 RGB 图片(堆栈 [1] 是我要显示的图像):
pix = hv.RGB(stack[1]).opts(
xaxis=None,
yaxis=None,
tools=['wheel_zoom','pan'],
default_tools=[],
active_tools=['wheel_zoom','pan']
)
它显示正常,但是当我使用滚轮缩放时,我可以缩小到超出图像限制的范围。有没有办法限制我的情节的限制,使其永远不会超过我的 data/image?
的边界可能有一个选项,但你可以为此使用一个挂钩
import holoviews as hv
hv.extension('bokeh')
import numpy as np
from functools import partial
def bounds_hook(plot, elem, xbounds=None, ybounds=None):
x_range = plot.handles['plot'].x_range
y_range = plot.handles['plot'].y_range
if xbounds is not None:
x_range.bounds = xbounds
else:
x_range.bounds = x_range.start, x_range.end
if ybounds is not None:
y_range.bounds = ybounds
else:
y_range.bounds = y_range.start, y_range.end
(hv.Image(np.random.rand(100,100)).opts(hooks=[bounds_hook]) +
hv.Image(np.random.rand(100,100)).opts(hooks=[partial(bounds_hook, xbounds=(-1, 1), ybounds=(-1,1))], axiswise=True))
def plot_limits(plot, element):
plot.handles['x_range'].min_interval = 100
plot.handles['x_range'].max_interval = 5500000
plot.handles['y_range'].min_interval = 500
plot.handles['y_range'].max_interval = 900000
hv.Image(np.random.rand(100,100)).opts=hooks=[plot_limits]