Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7644c5c

Browse files
authored
Merge pull request #21587 from meeseeksmachine/auto-backport-of-pr-21581-on-v3.5.x
Backport PR #21581 on branch v3.5.x (Fix RangeSlider.reset)
2 parents fbf81e7 + 56ec348 commit 7644c5c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,14 @@ def test_slider_horizontal_vertical():
743743
assert_allclose(box.bounds, [.25, 0, .5, 10/24])
744744

745745

746+
def test_slider_reset():
747+
fig, ax = plt.subplots()
748+
slider = widgets.Slider(ax=ax, label='', valmin=0, valmax=1, valinit=.5)
749+
slider.set_val(0.75)
750+
slider.reset()
751+
assert slider.val == 0.5
752+
753+
746754
@pytest.mark.parametrize("orientation", ["horizontal", "vertical"])
747755
def test_range_slider(orientation):
748756
if orientation == "vertical":
@@ -773,6 +781,9 @@ def test_range_slider(orientation):
773781
slider.set_val((-1, 10))
774782
assert_allclose(slider.val, (0, 1))
775783

784+
slider.reset()
785+
assert_allclose(slider.val, [0.1, 0.34])
786+
776787

777788
def check_polygon_selector(event_sequence, expected_result, selections_count):
778789
"""

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def disconnect(self, cid):
305305

306306
def reset(self):
307307
"""Reset the slider to the initial value."""
308-
if self.val != self.valinit:
308+
if np.any(self.val != self.valinit):
309309
self.set_val(self.valinit)
310310

311311

0 commit comments

Comments
 (0)