Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6a3d2e

Browse files
Better clipping
1 parent bb47e26 commit f6a3d2e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,12 @@ def _set_view_from_bbox(self, bbox, direction='in',
12151215
start_x = self.bbox.min[0]
12161216
stop_x = self.bbox.max[0]
12171217

1218+
# Clip to bounding box limits
1219+
start_x, stop_x = np.clip(sorted([start_x, stop_x]),
1220+
self.bbox.min[0], self.bbox.max[0])
1221+
start_y, stop_y = np.clip(sorted([start_y, stop_y]),
1222+
self.bbox.min[1], self.bbox.max[1])
1223+
12181224
# Move the center of the view to the center of the bbox
12191225
zoom_center_x = (start_x + stop_x)/2
12201226
zoom_center_y = (start_y + stop_y)/2

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,13 +1638,13 @@ def convert_lim(dmin, dmax):
16381638

16391639
@pytest.mark.parametrize("tool,button,key,expected",
16401640
[("zoom", MouseButton.LEFT, None, # zoom in
1641-
((0.26, 0.38), (0.43, 0.55), (0.54, 0.66))),
1641+
((0.00, 0.06), (0.01, 0.07), (0.02, 0.08))),
16421642
("zoom", MouseButton.LEFT, 'x', # zoom in
1643-
((0.39, 0.51), (0.20, 0.32), (-0.06, 0.06))),
1643+
((-0.01, 0.10), (-0.03, 0.08), (-0.06, 0.06))),
16441644
("zoom", MouseButton.LEFT, 'y', # zoom in
1645-
((-0.19, -0.07), (0.16, 0.28), (0.54, 0.66))),
1645+
((-0.07, 0.04), (-0.03, 0.08), (0.00, 0.11))),
16461646
("zoom", MouseButton.RIGHT, None, # zoom out
1647-
((0.26, 0.38), (0.43, 0.55), (0.54, 0.66))),
1647+
((-0.09, 0.15), (-0.07, 0.17), (-0.06, 0.18))),
16481648
("pan", MouseButton.LEFT, None,
16491649
((-0.70, -0.58), (-1.03, -0.91), (-1.27, -1.15))),
16501650
("pan", MouseButton.LEFT, 'x',

0 commit comments

Comments
 (0)