簡體   English   中英

如何限制 python holoviews 中的縮放最小和最大范圍?

[英]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']
)

它顯示得很好,但是當我使用滾輪縮放時,我可以縮小圖像的范圍。 有沒有辦法限制我的 plot 的限制,使其永遠不會超出我的數據/圖像的邊界?

可能有一個選項,但您可以為此使用掛鈎

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM