8000 Fix: have apply_aspect keep track of user-set limits by rcomer · Pull Request #30265 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix: have apply_aspect keep track of user-set limits #30265

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@
self._forward_navigation_events = forward_navigation_events
self._sharex = sharex
self._sharey = sharey
self._orig_xbound = None
self._orig_ybound = None
self.set_label(label)
self.set_figure(fig)
# The subplotspec needs to be set after the figure (so that
Expand Down Expand Up @@ -2019,8 +2021,8 @@

x_trf = self.xaxis.get_transform()
y_trf = self.yaxis.get_transform()
xmin, xmax = x_trf.transform(self.get_xbound())
ymin, ymax = y_trf.transform(self.get_ybound())
xmin, xmax = self._orig_xbound or x_trf.transform(self.get_xbound())
ymin, ymax = self._orig_ybound or y_trf.transform(self.get_ybound())
xsize = max(abs(xmax - xmin), 1e-30)
ysize = max(abs(ymax - ymin), 1e-30)

Expand Down Expand Up @@ -2072,18 +2074,26 @@
yc = 0.5 * (ymin + ymax)
y0 = yc - Ysize / 2.0
y1 = yc + Ysize / 2.0
self.set_ybound(y_trf.inverted().transform([y0, y1]))
if not self.get_autoscaley_on():
_log.warning("Ignoring fixed y limits to fulfill fixed data aspect "
"with adjustable data limits.")
self.set_ybound(y_trf.inverted().transform([y0, y1]))
self._orig_ybound = (ymin, ymax)
if self._orig_xbound is not None:
# We previously expanded x, so revert that
self.set_xbound(x_trf.inverted().transform([xmin, xmax]))

Check warning on line 2084 in lib/matplotlib/axes/_base.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/axes/_base.py#L2084

Added line #L2084 was not covered by tests
else:
xc = 0.5 * (xmin + xmax)
x0 = xc - Xsize / 2.0
x1 = xc + Xsize / 2.0
self.set_xbound(x_trf.inverted().transform([x0, x1]))
if not self.get_autoscalex_on():
_log.warning("Ignoring fixed x limits to fulfill fixed data aspect "
"with adjustable data limits.")
self.set_xbound(x_trf.inverted().transform([x0, x1]))
self._orig_xbound = (xmin, xmax)
if self._orig_ybound is not None:
# We previously expanded y, so revert that
self.set_ybound(y_trf.inverted().transform([ymin, ymax]))

Check warning on line 2096 in lib/matplotlib/axes/_base.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/axes/_base.py#L2096

Added line #L2096 was not covered by tests

def axis(self, arg=None, /, *, emit=True, **kwargs):
"""
Expand Down Expand Up @@ -3810,6 +3820,7 @@

>>> set_xlim(5000, 0)
"""
self._orig_xbound = None
if right is None and np.iterable(left):
left, right = left
if xmin is not None:
Expand Down Expand Up @@ -4059,6 +4070,7 @@

>>> set_ylim(5000, 0)
"""
self._orig_ybound = None
if top is None and np.iterable(bottom):
bottom, top = bottom
if ymin is not None:
Expand Down
Loading
0