Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining hard bounds when panning and zooming in bokeh backend #1019

Closed
philippjfr opened this issue Dec 15, 2016 · 12 comments · Fixed by #6056
Closed

Defining hard bounds when panning and zooming in bokeh backend #1019

philippjfr opened this issue Dec 15, 2016 · 12 comments · Fixed by #6056

Comments

@philippjfr
Copy link
Member

Currently when plotting using bokeh the axes are unbounded letting you zoom and pan to potentially empty parts of the data space. Since bokeh 0.11 it has been possible to bound the axis ranges to stop you from zooming or panning outside the desired region. We should decide how to expose this? Should axes ranges always be hard bounded or should setting an explicit dimension range bound them? There's a variety of behaviors we could consider here and just wanted to get discussion around this started.

@jlstevens
Copy link
Contributor

Sounds like something else that could go into the Dimension properties once that is implemented...

@philippjfr
Copy link
Member Author

Sounds like something else that could go into the Dimension properties once that is implemented...

We already have range and soft_range so I don't think anything new is needed. Just need to define the semantics.

@philippjfr
Copy link
Member Author

@jbednar Any opinion on this? I think it would be nice to offer hard bounds on the axes, should we say that if you explicitly set an Dimension range that becomes a hard-bound for the axis?

@philippjfr philippjfr added this to the v1.7.0 milestone Mar 11, 2017
@jbednar
Copy link
Member

jbednar commented Mar 11, 2017

My intuition is that we should be using the hard range of a Dimension automatically in this way, but I would have to get some experience with it in practice for different plot types to be sure about that and to know whether it should be configurable. I think I'd always want such bounds, but can't be sure until I experience it.

@philippjfr
Copy link
Member Author

philippjfr commented Mar 11, 2017

I think I'd always want such bounds, but can't be sure until I experience it.

I think so too, but not actually having used it I don't know either. I know that zooming out far beyond the actual data is rarely useful and usually bad behavior.

@jbednar
Copy link
Member

jbednar commented Mar 11, 2017

Right; "far beyond" is not useful and is very confusing. The question in my mind is about how big "far" is; we might need a configurable buffer, such that we can zoom out to 150% of the range, e.g., but not further. And of course anything like that then gets tricky for log axes, in which it would need to be 150% of the pixel area corresponding to the range. So, need to try it out to see if any such buffer is needed; it's simpler if it turns out not to be.

@philippjfr philippjfr modified the milestones: v2.0, v1.7.0 Mar 15, 2017
@LEMUEGGE
Copy link

Did anyone succeed in writing a work around solution for this? I think hard bounds are a very important feature, especially for boundaries of Image/Raster plots.

@philippjfr philippjfr modified the milestones: v2.0, v1.11 May 25, 2018
@philippjfr philippjfr modified the milestones: v1.11.0, v1.11.x Dec 27, 2018
@philippjfr philippjfr modified the milestones: v1.11.x, v1.12.0 Mar 22, 2019
@philippjfr philippjfr modified the milestones: v1.12.0, v1.12.x Apr 22, 2019
@philippjfr philippjfr modified the milestones: v1.12.x, v1.13.0 Oct 2, 2019
@philippjfr philippjfr modified the milestones: v1.13.0, v1.13.x Mar 3, 2020
@rynkk
Copy link

rynkk commented Apr 21, 2021

For anyone wondering, as of now, there's a workaround by accessing the underlying bokeh-figure:

import holoviews as hv
from bokeh.io import show
import dask.array as da

renderer = hv.renderer('bokeh')
sx = sy = 1000

arr = da.random.random((sx, sy))
fig = renderer.get_plot(hv.Image((range(sx), range(sy), arr)))

fig.state.x_range.bounds = (0, sx)
fig.state.y_range.bounds = (0, sy)

show(fig.state)

@philippjfr
Copy link
Member Author

Other suggestions:

import holoviews as hv
import dask.array as da
import panel as pn

sx = sy = 1000

arr = da.random.random((sx, sy))
img = hv.Image((range(sx), range(sy), arr))
fig = hv.render(img)

fig.x_range.bounds = (0, sx)
fig.y_range.bounds = (0, sy)

pn.panel(fig)

or using a hook:

import holoviews as hv
from bokeh.io import show
import dask.array as da

renderer = hv.renderer('bokeh')
sx = sy = 1000

arr = da.random.random((sx, sy))
img = hv.Image((range(sx), range(sy), arr))

def set_bounds(fig, element):
    fig.state.x_range.bounds = (0, sx)
    fig.state.y_range.bounds = (0, sy)

img.opts(hooks=[set_bounds])

@jbednar
Copy link
Member

jbednar commented Apr 21, 2021

Trying out the hook for that example makes me more confident that HoloViews should enforce hard bounds by default. It's a much better user experience. My guess is that now that HoloViews adds padding automatically, the padded range is already precisely the range that is also the most useful default hard bounds for pan and zoom. There are no doubt some cases and some users who want to be able to zoom out beyond that, but my gut is that those are very rare and that the current behavior is much more surprising and annoying to a huge class of users than it will be for those rare users who find that they want it to behave the current way. So it's important to be configurable, but I am still strongly advocating for enabling hard bounds by default.

It would be nice to have a dev build of the HoloViews website where such bounds are enabled by default for all plots and we can try them out with all the different plot types in the reference gallery to further validate it.

@philippjfr philippjfr modified the milestones: v1.14.x, v2.0 May 23, 2021
@droumis
Copy link
Member

droumis commented Oct 19, 2023

you can now achieve this with HoloView's support of backend_opts, e.g.:

backend_opts={
"x_range.bounds": (0, 10),
"y_range.bounds": (0, 20)
}

Update: use apply_hard_bounds=True as in #6056

@droumis droumis moved this to WIP in CZI R5 neuro Jan 1, 2024
@droumis droumis self-assigned this Jan 4, 2024
@droumis droumis moved this from WIP to Needs review in CZI R5 neuro Apr 15, 2024
@droumis droumis moved this from Needs review to Done in CZI R5 neuro Jun 23, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants