8000 Backport PR #21581: Fix RangeSlider.reset · meeseeksmachine/matplotlib@ac93275 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac93275

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR matplotlib#21581: Fix RangeSlider.reset
1 parent f855dde commit ac93275

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
@@ -298,6 +298,14 @@ def test_slider_horizontal_vertical():
298298
assert_allclose(box.bounds, [0, 0, 1, 10/24])
299299

300300

301+
def test_slider_reset():
302+
fig, ax = plt.subplots()
303+
slider = widgets.Slider(ax=ax, label='', valmin=0, valmax=1, valinit=.5)
304+
slider.set_val(0.75)
305+
slider.reset()
306+
assert slider.val == 0.5
307+
308+
301309
@pytest.mark.parametrize("orientation", ["horizontal", "vertical"])
302310
def test_range_slider(orientation):
303311
if orientation == "vertical":
@@ -328,6 +336,9 @@ def test_range_slider(orientation):
328336
slider.set_val((-1, 10))
329337
assert_allclose(slider.val, (0, 1))
330338

339+
slider.reset()
340+
assert_allclose(slider.val, [0.1, 0.34])
341+
331342

332343
def check_polygon_selector(event_sequence, expected_result, selections_count):
333344
"""

lib/matplotlib/widgets.py

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

304304
def reset(self):
305305
"""Reset the slider to the initial value."""
306-
if self.val != self.valinit:
306+
if np.any(self.val != self.valinit):
307307
self.set_val(self.valinit)
308308

309309

0 commit comments

Comments
 (0)
0