-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added a new public API update_range to Slider widget. It helps to change the valmin and valmax of the Slider #20579
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and welcome to Matplotlib!
@BSNayal In general, you should not merge master into your feature branch. Instead rebase your branch on master if needed (i.e. if you need some new code from master or need to resolve a conflict). Otherwise, it's ok if the feature branch is behind master. |
Sure. |
I am currently working on windows environment. |
All the tests have to pass, but hopefully you can fix them without access to other operating systems. |
One thing to consider is that #19265 will have an effect on this, or vice versa. |
lib/matplotlib/widgets.py
Outdated
@@ -529,6 +529,25 @@ def on_changed(self, func): | |||
""" | |||
return self._observers.connect('changed', lambda val: func(val)) | |||
|
|||
def set_limits(self, vmin=None, vmax=None): | |||
"""Update the range of the slider""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Update the range of the slider""" | |
"""Update the limits of the slider.""" |
1. Add a set_limits function to the SliderBase class
Please rebase on master to fix the doc build. |
1. Add a set_limits function to the SliderBase class
can we create timer based image comparison test cases ? My scenario : the plot is shown with the slider, after 1 sec I change the val of the slider and after 2 sec I change the limits of the slider. So once the limits are changed after that the snapshot should be taken , but in my case when the plot is shown the image is captured at that moment |
The plots are never shown in tests; they are not interactive, ergo, there's no need to wait to see what changes. What's captured is always the last appearance of the figure. |
@@ -306,6 +306,19 @@ def reset(self): | |||
if self.val != self.valinit: | |||
self.set_val(self.valinit) | |||
|
|||
def set_limits(self, vmin=None, vmax=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match __init__
, these should probably be named:
def set_limits(self, vmin=None, vmax=None): | |
def set_limits(self, valmin=None, valmax=None): |
@@ -583,6 +596,18 @@ def on_changed(self, func): | |||
""" | |||
return self._observers.connect('changed', lambda val: func(val)) | |||
|
|||
def set_limits(self, vmin=None, vmax=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above about argument names.
self.hline.set_ydata(self.valinit) | ||
else: | ||
self.vline.set_xdata(self.valinit) | ||
|
||
|
||
class RangeSlider(SliderBase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does RangeSlider
also need some custom set_limits
, or is the base class implementation enough?
@BSNayal Could you use |
Hi @BSNayal what are your plans for this PR? If you no longer have time for it then I'd be happy to pick it up and finish the good work you started. |
@BSNayal Are you still interested in working on this? I'm going to push this to 3.8. |
(sorry miss-clicked, did not mean to close) |
PR Summary
This PR creates a new public API for slider . It is called the udpate_range(). So when a slider has been created and later on we want to update its range we can use this function
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).