Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Backport PR #22711 on branch v3.5.x (RangeSlider handle set_val bugfix)#22729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletionlib/matplotlib/tests/test_widgets.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1037,19 +1037,30 @@ def test_range_slider(orientation):
# Check initial value is set correctly
assert_allclose(slider.val, (0.1, 0.34))

def handle_positions(slider):
if orientation == "vertical":
return [h.get_ydata()[0] for h in slider._handles]
else:
return [h.get_xdata()[0] for h in slider._handles]

slider.set_val((0.2, 0.6))
assert_allclose(slider.val, (0.2, 0.6))
assert_allclose(handle_positions(slider), (0.2, 0.6))

box = slider.poly.get_extents().transformed(ax.transAxes.inverted())
assert_allclose(box.get_points().flatten()[idx], [0.2, .25, 0.6, .75])

slider.set_val((0.2, 0.1))
assert_allclose(slider.val, (0.1, 0.2))
assert_allclose(handle_positions(slider), (0.1, 0.2))

slider.set_val((-1, 10))
assert_allclose(slider.val, (0, 1))
assert_allclose(handle_positions(slider), (0, 1))

slider.reset()
assert_allclose(slider.val, [0.1, 0.34])
assert_allclose(slider.val, (0.1, 0.34))
assert_allclose(handle_positions(slider), (0.1, 0.34))


def check_polygon_selector(event_sequence, expected_result, selections_count):
Expand Down
24 changes: 20 additions & 4 deletionslib/matplotlib/widgets.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,10 @@ def _update_val_from_pos(self, pos):
val = self._max_in_bounds(pos)
self.set_max(val)
if self._active_handle:
self._active_handle.set_xdata([val])
if self.orientation == "vertical":
self._active_handle.set_ydata([val])
else:
self._active_handle.set_xdata([val])

def _update(self, event):
"""Update the slider position."""
Expand All@@ -836,11 +839,16 @@ def _update(self, event):
return

# determine which handle was grabbed
handle = self._handles[
np.argmin(
if self.orientation == "vertical":
handle_index = np.argmin(
np.abs([h.get_ydata()[0] - event.ydata for h in self._handles])
)
else:
handle_index = np.argmin(
np.abs([h.get_xdata()[0] - event.xdata for h in self._handles])
)
]
handle = self._handles[handle_index]

# these checks ensure smooth behavior if the handles swap which one
# has a higher value. i.e. if one is dragged over and past the other.
if handle is not self._active_handle:
Expand DownExpand Up@@ -907,14 +915,22 @@ def set_val(self, val):
xy[2] = .75, val[1]
xy[3] = .75, val[0]
xy[4] = .25, val[0]

self._handles[0].set_ydata([val[0]])
self._handles[1].set_ydata([val[1]])
else:
xy[0] = val[0], .25
xy[1] = val[0], .75
xy[2] = val[1], .75
xy[3] = val[1], .25
xy[4] = val[0], .25

self._handles[0].set_xdata([val[0]])
self._handles[1].set_xdata([val[1]])

self.poly.xy = xy
self.valtext.set_text(self._format(val))

if self.drawon:
self.ax.figure.canvas.draw_idle()
self.val = val
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp