Skip to content

Don't forget to disable autoscaling after interactive zoom. #20662

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 4 additions & 11 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4292,33 +4292,24 @@ def _set_view_from_bbox(self, bbox, direction='in',
Whether this axis is twinned in the *y*-direction.
"""
if len(bbox) == 3:
Xmin, Xmax = self.get_xlim()
Ymin, Ymax = self.get_ylim()

xp, yp, scl = bbox # Zooming code

if scl == 0: # Should not happen
scl = 1.

if scl > 1:
direction = 'in'
else:
direction = 'out'
scl = 1/scl

# get the limits of the axes
tranD2C = self.transData.transform
xmin, ymin = tranD2C((Xmin, Ymin))
xmax, ymax = tranD2C((Xmax, Ymax))

(xmin, ymin), (xmax, ymax) = self.transData.transform(
np.transpose([self.get_xlim(), self.get_ylim()]))
# set the range
xwidth = xmax - xmin
ywidth = ymax - ymin
xcen = (xmax + xmin)*.5
ycen = (ymax + ymin)*.5
xzc = (xp*(scl - 1) + xcen)/scl
yzc = (yp*(scl - 1) + ycen)/scl

bbox = [xzc - xwidth/2./scl, yzc - ywidth/2./scl,
xzc + xwidth/2./scl, yzc + ywidth/2./scl]
elif len(bbox) != 4:
Expand Down Expand Up @@ -4371,8 +4362,10 @@ def _set_view_from_bbox(self, bbox, direction='in',

if not twinx and mode != "y":
self.set_xbound(new_xbound)
self.set_autoscalex_on(False)
if not twiny and mode != "x":
self.set_ybound(new_ybound)
self.set_autoscaley_on(False)

def start_pan(self, x, y, button):
"""
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def test_interactive_zoom():
tb.zoom()
assert ax.get_navigate_mode() is None

assert not ax.get_autoscalex_on() and not ax.get_autoscaley_on()


def test_toolbar_zoompan():
expected_warning_regex = (
Expand Down