diff --git a/lib/matplotlib/tests/test_widgets.py b/lib/matplotlib/tests/test_widgets.py index f50402a20a15..0e4a7e7daa68 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -743,6 +743,14 @@ def test_slider_horizontal_vertical(): assert_allclose(box.bounds, [.25, 0, .5, 10/24]) +def test_slider_reset(): + fig, ax = plt.subplots() + slider = widgets.Slider(ax=ax, label='', valmin=0, valmax=1, valinit=.5) + slider.set_val(0.75) + slider.reset() + assert slider.val == 0.5 + + @pytest.mark.parametrize("orientation", ["horizontal", "vertical"]) def test_range_slider(orientation): if orientation == "vertical": @@ -773,6 +781,9 @@ def test_range_slider(orientation): slider.set_val((-1, 10)) assert_allclose(slider.val, (0, 1)) + slider.reset() + assert_allclose(slider.val, [0.1, 0.34]) + def check_polygon_selector(event_sequence, expected_result, selections_count): """ diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 35d9ed3bfe4f..c34eaae792d3 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -305,7 +305,7 @@ def disconnect(self, cid): def reset(self): """Reset the slider to the initial value.""" - if self.val != self.valinit: + if np.any(self.val != self.valinit): self.set_val(self.valinit)