-
Notifications
You must be signed in to change notification settings - Fork 20
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
Set initial slider position in Hyperslicer #276
Comments
Hi @EvdWee I'm glad youre finding it useful! Unfortunately the inability to set initial positions is one of the longstanding issues with this library that turns out to be surprisingly complicated to fix. See more details here: #183 That said you can hopefully use the below %matplotlib ipympl
import matplotlib.pyplot as plt
import numpy as np
from mpl_interactions import hyperslicer
def set_param_indices(controls, setters: dict[str, int] = None, **kwargs):
"""
Set initial values of sliders assuming that you
are creating ipywidgets sliders, not Matpotlib sliders.
Parameters
----------
controls : controls object
setters : dict
A dictionary of names mapping to indices. Necessary in case one of the slider
names is invalid as a kwarg to function (e.g. if it has a space in it).
** kwargs:
pairs of param names and index to set the slider to.
NOTE: the values must be integer indices, not necessarily the
value that you expect the slider to display.
"""
if setters is not None:
kwargs.update(setters)
for name, idx in kwargs.items():
controls.controls[name].children[0].value = idx
fig = plt.figure()
array = np.random.rand(5, 2, 512, 512)
control1 = hyperslicer(
array, vmin=np.min(array), vmax=np.max(array), names=("Z Position", "channel")
)
# can set either using setters or kwargs
set_param_indices(control1, setters={"Z Position": 3}, channel=1)
plt.show() note: This is setting the index, not the value. So in the case in hyperslicer yo uhave where the z indices map to values you need to set the index that would correspond to I'm sorry this is confusing, it's all a consequence of design choices I made several years ago that made sense at the time but have made things difficult now :( |
Thanks for the quick response. This function seems to be a bit more trustworthy than my fix I just found: |
Hello,
I am using hyperslicer to visualize an image stack (3D array) and navigate through the stack. This works nicely, but I would like to set the initial position of the slider to a specific value, not just the first image in the stack.
How to do this with the hyperslicer() function? My code looks something like this:
The text was updated successfully, but these errors were encountered: