Skip to content

Commit d95e3f8

Browse files
authored
Merge pull request #14990 from anntzer/mixedscaleaspect
Fix nonsensical transform in mixed-mode axes aspect computation.
2 parents cee82fb + 6108d49 commit d95e3f8

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lib/matplotlib/axes/_base.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -1410,12 +1410,10 @@ def get_data_ratio(self):
14101410
-----
14111411
This method is intended to be overridden by new projection types.
14121412
"""
1413-
trf_xmin, trf_xmax = map(
1414-
self.xaxis.get_transform().transform, self.get_xbound())
1415-
trf_ymin, trf_ymax = map(
1416-
self.yaxis.get_transform().transform, self.get_ybound())
1417-
xsize = max(abs(trf_xmax - trf_xmin), 1e-30)
1418-
ysize = max(abs(trf_ymax - trf_ymin), 1e-30)
1413+
txmin, txmax = self.xaxis.get_transform().transform(self.get_xbound())
1414+
tymin, tymax = self.yaxis.get_transform().transform(self.get_ybound())
1415+
xsize = max(abs(txmax - txmin), 1e-30)
1416+
ysize = max(abs(tymax - tymin), 1e-30)
14191417
return ysize / xsize
14201418

14211419
@cbook.deprecated("3.2")
@@ -1492,8 +1490,8 @@ def apply_aspect(self, position=None):
14921490

14931491
x_trf = self.xaxis.get_transform()
14941492
y_trf = self.yaxis.get_transform()
1495-
xmin, xmax = map(x_trf.transform, self.get_xbound())
1496-
ymin, ymax = map(y_trf.transform, self.get_ybound())
1493+
xmin, xmax = x_trf.transform(self.get_xbound())
1494+
ymin, ymax = y_trf.transform(self.get_ybound())
14971495
xsize = max(abs(xmax - xmin), 1e-30)
14981496
ysize = max(abs(ymax - ymin), 1e-30)
14991497

@@ -1507,8 +1505,8 @@ def apply_aspect(self, position=None):
15071505
return
15081506

15091507
dL = self.dataLim
1510-
x0, x1 = map(x_trf.inverted().transform, dL.intervalx)
1511-
y0, y1 = map(y_trf.inverted().transform, dL.intervaly)
1508+
x0, x1 = x_trf.transform(dL.intervalx)
1509+
y0, y1 = y_trf.transform(dL.intervaly)
15121510
xr = 1.05 * (x1 - x0)
15131511
yr = 1.05 * (y1 - y0)
15141512

@@ -1544,12 +1542,12 @@ def apply_aspect(self, position=None):
15441542
yc = 0.5 * (ymin + ymax)
15451543
y0 = yc - Ysize / 2.0
15461544
y1 = yc + Ysize / 2.0
1547-
self.set_ybound(*map(y_trf.inverted().transform, (y0, y1)))
1545+
self.set_ybound(y_trf.inverted().transform([y0, y1]))
15481546
else:
15491547
xc = 0.5 * (xmin + xmax)
15501548
x0 = xc - Xsize / 2.0
15511549
x1 = xc + Xsize / 2.0
1552-
self.set_xbound(*map(x_trf.inverted().transform, (x0, x1)))
1550+
self.set_xbound(x_trf.inverted().transform([x0, x1]))
15531551

15541552
def axis(self, *args, emit=True, **kwargs):
15551553
"""

lib/matplotlib/tests/test_axes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6554,9 +6554,10 @@ 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+
assert ax.get_xlim() == pytest.approx([1*10**(1/2), 100/10**(1/2)])
6563+
assert ax.get_ylim() == (1 / 101, 1 / 11)

0 commit comments

Comments
 (0)