-
Notifications
You must be signed in to change notification settings - Fork 19
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
Handle ipywidget sliders in Controls.save_animation #181
Comments
Hi @redeboer thanks for the excellent bug report and quick fix!
It most definitely is supposed to work with those! In fact originally those are all that were supported. Is there a reason you are manually creating the sliders? A big benefit for me of this package is that it will autocreate the sliders for you based on the shorthands of tuples or passing in arrays. So instead of defining
If you create them with a controls object then you can still directly access the sliders by:
All that aside I think you're right that a fix is need and your fix looks good on quick glance, I can review it tonight. After writing the above I wonder if it might be nice to be to directly set the values of the parameters by accessing the controls objeect. Something like |
That isn't quite true :(. For ipywidgets if
|
(for future me) I think the way here is to make from traitlets import HasTraits, Int
class controls(HasTraits):
whatever = Int(30)
beep = controls()
boop = controls()
beep.add_traits(blarg = Int())
beep.blarg = 2
boop.blarg # AttributeError |
You're welcome! I'm quite new to widgets etc. and avoided them so far, but mpl-interactions makes it much easier to use them. So thanks again :)
That's true, originally I also followed the 'auto-create style' from the documentation. But indeed, as you note, it's currently a bit tedious to programmatically modify slider values. For instance,
So it could be that I misunderstood some things, particularly how to work with the generated
That syntax would be nice indeed! Personally, I have my reservations though about adding too many convenient short-cuts. So in this example, I would prefer something more object-oriented, like slider = controls.controls["beta"]
slider.label = "\\beta"
slider.min = 2.2
slider.set_range(0, 2.5)
slider.n_points = 10 (or some variation thereof). Reason is that such methods and attributes (can) document themselves in an API and make it easier for the developer to understand the codebase (or for a user who has some particular requirements). Convenience often comes at the cost of maintainability and can make the framework restricted to particular use cases. Background: I was writing some functions that generate interactive plots from arbitrary sympy expressions (remaining free symbols become sliders, etc.). That's why I wanted to set latex labels for the sliders and initialize the sliders with some suggested parameter value. |
Part of what I'm trying achieve is to this library handle all the complexity of the differences between ipywidgets and maptlotlib widgets. Then you can use this in a function and not have to worry about a different API depending on if the user is running your code from a notebook or not. So I guess that any solution will need to both:
I'll think about this more and open an issue with potential options - your thoughts and/or suggestions are of course welcome.
Nah I think you did it right. The HBox structure is only relevant if the sliders are autogenerated which is captured in the first
That sounds very cool! If it's not already I'd definitely encourage you to make this available as a standalone package (there's also https://github.com/matplotlib/matplotlib-extension-cookiecutter if you need a start point) |
Bug report
Hi @ianhi and contributors, thanks a lot for creating this nice interface to matplotlib!
Following https://mpl-interactions.readthedocs.io/en/0.17.8/gallery/mpl-sliders-same-figure.html, I've been trying to use
FloatSlider
s fromipywidgets
as controllers, because I find them more convenient than Matplotlib sliders. Not sure if mpl-interactions is supposed to work like that, but it worked well so far, up to saving an animation.Bug summary
Controls.save_animation
cannot handleFloatSlider
orIntSlider
fromipywidgets
.Code for reproduction
Modified from basic example:
Actual outcome
Expected outcome
After a small bug fix (see #182), these are the resulting gifs:
FloatSlider
)IntSlider
)Version Info
ipympl
jupyterlab==3.0.14
The text was updated successfully, but these errors were encountered: