Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2566eaa

Browse filesBrowse files
RangeSlider handle set_val bugfix
1 parent 2e921df commit 2566eaa
Copy full SHA for 2566eaa

File tree

Expand file treeCollapse file tree

1 file changed

+23
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-5
lines changed

‎lib/matplotlib/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/widgets.py
+23-5Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,10 @@ def _update_val_from_pos(self, pos):
813813
val = self._max_in_bounds(pos)
814814
self.set_max(val)
815815
if self._active_handle:
816-
self._active_handle.set_xdata([val])
816+
if self.orientation == "vertical":
817+
self._active_handle.set_ydata([val])
818+
else:
819+
self._active_handle.set_xdata([val])
817820

818821
def _update(self, event):
819822
"""Update the slider position."""
@@ -835,12 +838,19 @@ def _update(self, event):
835838
self._active_handle = None
836839
return
837840

838-
# determine which handle was grabbed
839-
handle = self._handles[
840-
np.argmin(
841+
if self.orientation == "vertical":
842+
# determine which handle was grabbed
843+
event_handle = np.argmin(
844+
np.abs([h.get_ydata()[0] - event.ydata for h in self._handles])
845+
)
846+
handle = self._handles[event_handle]
847+
else:
848+
# determine which handle was grabbed
849+
event_handle = np.argmin(
841850
np.abs([h.get_xdata()[0] - event.xdata for h in self._handles])
842851
)
843-
]
852+
handle = self._handles[event_handle]
853+
844854
# these checks ensure smooth behavior if the handles swap which one
845855
# has a higher value. i.e. if one is dragged over and past the other.
846856
if handle is not self._active_handle:
@@ -904,14 +914,22 @@ def set_val(self, val):
904914
xy[2] = .75, val[1]
905915
xy[3] = .75, val[0]
906916
xy[4] = .25, val[0]
917+
918+
self._handles[0].set_ydata([val[0]])
919+
self._handles[1].set_ydata([val[1]])
907920
else:
908921
xy[0] = val[0], .25
909922
xy[1] = val[0], .75
910923
xy[2] = val[1], .75
911924
xy[3] = val[1], .25
912925
xy[4] = val[0], .25
926+
927+
self._handles[0].set_xdata([val[0]])
928+
self._handles[1].set_xdata([val[1]])
929+
913930
self.poly.xy = xy
914931
self.valtext.set_text(self._format(val))
932+
915933
if self.drawon:
916934
self.ax.figure.canvas.draw_idle()
917935
self.val = val

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.