Giter Site home page Giter Site logo

Comments (3)

EvdWee avatar EvdWee commented on August 18, 2024

I have found the dictionary with the slider position, and can modify it, but it does not update the slider position:

MicrosoftTeams-image (5)

from mpl-interactions.

ianhi avatar ianhi commented on August 18, 2024

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.

EvdWee avatar EvdWee commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.