Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Update Slider Range (valmin and valmax)#30556
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 ourterms of service andprivacy 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?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Added two functions:1. update_range in class Slider2. update_bounds in class 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.
Thanks for the contribution.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/widgets.py Outdated
val=self._value_in_bounds(self.val) | ||
ifvalnotin [None,self.val]: |
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.
Can val be None here? I thought_value_in_bounds
always returns a value (coerced if necessary). Please recheck.
Also, please add a remark to the docstring what happens to the value if bounds change so that it's outside.
Also, please check what happens to the existing value if it is in bounds and document that. Can it change because the steps are now different.
Also, I thinkset_val()
updates the slider rectangle so even if the value does not change, e.g. val=5 valstep1; change range from (1, 7) to (3, 9) -> val does not change, but the slider position changes.
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.
Here's an example where_value_in_bounds
returnsNone
:
matplotlib/lib/matplotlib/widgets.py
Lines 511 to 517 in70502cf
def_value_in_bounds(self,val): | |
"""Makes sure *val* is with given bounds.""" | |
val=self._stepped_value(val) | |
ifval<=self.valmin: | |
ifnotself.closedmin: | |
return |
Here's another example where the_value_in_bounds
result is checked forNone
:
matplotlib/lib/matplotlib/widgets.py
Lines 447 to 449 in70502cf
valinit=self._value_in_bounds(valinit) | |
ifvalinitisNone: | |
valinit=valmin |
Whether the value is within or outside bounds does not matter; slider, bounds, and val change accordingly. (I don't know how to document that.)
Yes, regarding your last statement. The val does not change, but the slider position changes. That is intended.5
is within(1, 7)
and within(3, 9)
as well, soval
doesNOT change. The slider position changes because the limits change: in(1, 7)
,5
is4
positions away, but in(3, 9)
,5
is only2
positions away, and so the slider goes downward.
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.
Oh, nevermind the None value. I've overlooked this.
slider, bounds, and val change accordingly. (I don't know how to document that.)
Something like "The slider value is coerced to the nearest valid position based on the limits and valstep." (if that's the actual behavior, which I would intuitively expect).
The slider position changes
Ok so there's some kind of automatic update/draw triggered. That's what I wanted to ensure [not an expert in the widgets topic.
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.
Yes, there is an automatic update triggered.
Also, I have updated the docstring as per your suggestion (slider value is coerced to nearest . . .).
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
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.
I'm considering a name different fromupdate_range()
because if we want to later expand this toRangeSlider
, thererange also has a dedicated and different meaning.
update_limits()
would be good in terms of valmin, valmax, but is slightly worse in expressing that it also covers valstep. It would be nice if we could come up with something even better, but if not I would go withupdate_limits
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
|
Oh, okay, yes, that's confusing. You can set the appropriate function name. |
timhoffm commentedSep 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Semi-OT: While thinking about naming and how
Overall, the interaction between val, array-like valstep and valmin/valmax is ill-defined. Why is this relevant for this PR? Selective changes of valstep, valmin, valmax make this inconsistency worse. The way out of the inconsistency may affect the the way we specify the data range and thus how the API to modify must look like. Edit: Additional issue: we cannot use We can later add that behavior by using custom sentinels as default. Edit: Ok the way forward is the following:
|
vs.
I'm confused. Are we going with As an alternative, what are your thoughts on implementinggetter/setter properties instead? When But you're right that a check is required. About that, Also, should there be a check for Regarding the sentinel, some functions tend to use the Just a thought, maybe we could do the inverse and set 'none'(string) as the sentinel? |
timhoffm commentedSep 26, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
We should possibly make the attributes private. Individual setters are not a good option. They are more cumbersome to use I think the boundary conditions for explict step values are not well thought through and not handled consistently. But the problem is not getting worse if we limit ourselves for now to the "always set everything" approach. As it is as good or bad as setting on Yes, a sentinel object, would be the way to go. We have one here matplotlib/lib/matplotlib/artist.py Line 110 in5cd38c3
But as said, partial setting introduces additional complexity and the need for better validation. I propose to defer this we can later always move from
to
|
Added two functions:
PR summary
This PR is a solution to issue#30555 and thisdiscourse.matplotlib.org post.
This PRcloses#30555.
Thisvideo demonstrates the change.