Comments (3)
I have found the dictionary with the slider position, and can modify it, but it does not update the slider position:
from mpl-interactions.
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 set_param_indices
function to accomplish what you want:
%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 0.9
rather than setting 0.9
.
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 :(
from mpl-interactions.
Thanks for the quick response. This function seems to be a bit more trustworthy than my fix I just found:
control1.vbox.children[0].children[0].value=3
from mpl-interactions.
Related Issues (20)
- panhandler doesn't work when you call from another function HOT 4
- Add example of using mpl-interactions as an engine for updating without sliders HOT 2
- Better testing
- Add conda forge install instructions
- Syntax Error in controller.py HOT 7
- add `eventplot` function
- Dynamically update `fontdict` for `iplt.text`
- Didn't find the package using Mamba HOT 2
- sliders not showing with ipywidgets 8.0.1 HOT 2
- NameError: name 'display' is not defined HOT 2
- image_segmenter: Enable saving of verts or path coordinates for a image_segmenter object HOT 11
- Git-Issue: Can't commit to my fork of mpl-interactions HOT 5
- Hyperslicer not producing same image as imshow for xarray HOT 3
- Check behavior of hyperslicer `names` and `axes` arguments.
- panhandler not working when plot embedded in pyqt5 HOT 2
- joss review: installation issues HOT 3
- joss review: writing comments HOT 2
- Joss review: authorship HOT 7
- [JOSS review]: state of the field HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpl-interactions.