8000 Merge pull request #25340 from QuLogic/rangeslider-set-clip · matplotlib/matplotlib@fbe7a44 · GitHub
[go: up one dir, main page]

Skip to content

Commit fbe7a44

Browse files
authored
Merge pull request #25340 from QuLogic/rangeslider-set-clip
Fix RangeSlider.set_val when outside existing value
2 parents 52dd5ec + a0d25af commit fbe7a44

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,12 @@ def handle_positions(slider):
12971297
else:
12981298
return [h.get_xdata()[0] for h in slider._handles]
12991299

1300-
slider.set_val((0.2, 0.6))
1301-
assert_allclose(slider.val, (0.2, 0.6))
1302-
assert_allclose(handle_positions(slider), (0.2, 0.6))
1300+
slider.set_val((0.4, 0.6))
1301+
assert_allclose(slider.val, (0.4, 0.6))
1302+
assert_allclose(handle_positions(slider), (0.4, 0.6))
13031303

13041304
box = slider.poly.get_extents().transformed(ax.transAxes.inverted())
1305-
assert_allclose(box.get_points().flatten()[idx], [0.2, .25, 0.6, .75])
1305+
assert_allclose(box.get_points().flatten()[idx], [0.4, .25, 0.6, .75])
13061306

13071307
slider.set_val((0.2, 0.1))
13081308
assert_allclose(slider.val, (0.1, 0.2))

lib/matplotlib/widgets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def __init__(
702702
valmin, valmax, valfmt, dragging, valstep)
703703

704704
# Set a value to allow _value_in_bounds() to work.
705-
self.val = [valmin, valmax]
705+
self.val = (valmin, valmax)
706706
if valinit is None:
707707
# Place at the 25th and 75th percentiles
708708
extent = valmax - valmin
@@ -947,9 +947,9 @@ def set_val(self, val):
947947
"""
948948
val = np.sort(val)
949949
_api.check_shape((2,) 6FC8 , val=val)
950-
vmin, vmax = val
951-
vmin = self._min_in_bounds(vmin)
952-
vmax = self._max_in_bounds(vmax)
950+
# Reset value to allow _value_in_bounds() to work.
951+
self.val = (self.valmin, self.valmax)
952+
vmin, vmax = self._value_in_bounds(val)
953953
self._update_selection_poly(vmin, vmax)
954954
if self.orientation == "vertical":
955955
self._handles[0].set_ydata([vmin])

0 commit comments

Comments
 (0)
0