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

Skip to content

Commit 418a1ad

Browse files
committed
Fix nonsensical transform in mixed-mode axes aspect computation.
1 parent bb6a4af commit 418a1ad

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,8 @@ def apply_aspect(self, position=None):
15071507
return
15081508

15091509
dL = self.dataLim
1510-
x0, x1 = map(x_trf.inverted().transform, dL.intervalx)
1511-
y0, y1 = map(y_trf.inverted().transform, dL.intervaly)
1510+
x0, x1 = map(x_trf.transform, dL.intervalx)
1511+
y0, y1 = map(y_trf.transform, dL.intervaly)
15121512
xr = 1.05 * (x1 - x0)
15131513
yr = 1.05 * (y1 - y0)
15141514

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6554,9 +6554,12 @@ def test_aspect_nonlinear_adjustable_datalim():
65546554

65556555
ax = fig.add_axes([.1, .1, .8, .8]) # Square.
65566556
ax.plot([.4, .6], [.4, .6]) # Set minpos to keep logit happy.
6557-
ax.set(xscale="log", xlim=(1, 10),
6558-
yscale="logit", ylim=(1/11, 1/1001),
6557+
ax.set(xscale="log", xlim=(1, 100),
6558+
yscale="logit", ylim=(1 / 101, 1 / 11),
65596559
aspect=1, adjustable="datalim")
65606560
ax.margins(0)
65616561
ax.apply_aspect()
6562-
assert ax.get_xlim() == pytest.approx(np.array([1/10, 10]) * np.sqrt(10))
6562+
# Currently the autoscaler chooses to reduce the x-limits by half a decade
6563+
# on each end, but this may change later.
6564+
assert ax.get_xlim() == pytest.approx([1*10**(1/2), 100/10**(1/2)])
6565+
assert ax.get_ylim() == (1 / 101, 1 / 11)

0 commit comments

Comments
 (0)