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 31a6cc9

Browse filesBrowse files
committed
Fix keeping bound when initialising SpanSelector.
1 parent 6786f43 commit 31a6cc9
Copy full SHA for 31a6cc9

File tree

Expand file treeCollapse file tree

2 files changed

+35
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-1
lines changed

‎lib/matplotlib/tests/test_widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_widgets.py
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,35 @@ def test_tool_line_handle():
302302
assert tool_line_handle.positions == positions
303303

304304

305+
@pytest.mark.parametrize('direction', ("horizontal", "vertical"))
306+
def test_span_selector_bound(direction):
307+
fig, ax = plt.subplots(1, 1)
308+
ax.plot([10, 20], [10, 30])
309+
ax.figure.canvas.draw()
310+
x_bound = ax.get_xbound()
311+
y_bound = ax.get_ybound()
312+
313+
tool = widgets.SpanSelector(ax, print, direction, interactive=True)
314+
assert ax.get_xbound() == x_bound
315+
assert ax.get_ybound() == y_bound
316+
317+
bound = x_bound if direction == 'horizontal' else y_bound
318+
assert tool._edge_handles.positions == list(bound)
319+
320+
press_data = [10.5, 11.5]
321+
move_data = [11, 13] # Updating selector is done in onmove
322+
release_data = move_data
323+
do_event(tool, 'press', xdata=press_data[0], ydata=press_data[1], button=1)
324+
do_event(tool, 'onmove', xdata=move_data[0], ydata=move_data[1], button=1)
325+
326+
assert ax.get_xbound() == x_bound
327+
assert ax.get_ybound() == y_bound
328+
329+
index = 0 if direction == 'horizontal' else 1
330+
handle_positions = [press_data[index], release_data[index]]
331+
assert tool._edge_handles.positions == handle_positions
332+
333+
305334
def check_lasso_selector(**kwargs):
306335
ax = get_ax()
307336

‎lib/matplotlib/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/widgets.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,12 @@ def new_axes(self, ax):
21562156
self.artists.append(self._rect)
21572157

21582158
def _setup_edge_handle(self, props):
2159-
self._edge_handles = ToolLineHandles(self.ax, self.extents,
2159+
# Define initial position using the axis bounds to keep the same bounds
2160+
if self.direction == 'horizontal':
2161+
positions = self.ax.get_xbound()
2162+
else:
2163+
positions = self.ax.get_ybound()
2164+
self._edge_handles = ToolLineHandles(self.ax, positions,
21602165
direction=self.direction,
21612166
line_props=props,
21622167
useblit=self.useblit)

0 commit comments

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