Skip to content
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
22 changes: 10 additions & 12 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,12 +1410,10 @@ def get_data_ratio(self):
-----
This method is intended to be overridden by new projection types.
"""
trf_xmin, trf_xmax = map(
self.xaxis.get_transform().transform, self.get_xbound())
trf_ymin, trf_ymax = map(
self.yaxis.get_transform().transform, self.get_ybound())
xsize = max(abs(trf_xmax - trf_xmin), 1e-30)
ysize = max(abs(trf_ymax - trf_ymin), 1e-30)
txmin, txmax = self.xaxis.get_transform().transform(self.get_xbound())
tymin, tymax = self.yaxis.get_transform().transform(self.get_ybound())
xsize = max(abs(txmax - txmin), 1e-30)
ysize = max(abs(tymax - tymin), 1e-30)
return ysize / xsize

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

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

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

dL = self.dataLim
x0, x1 = map(x_trf.inverted().transform, dL.intervalx)
y0, y1 = map(y_trf.inverted().transform, dL.intervaly)
x0, x1 = x_trf.transform(dL.intervalx)
y0, y1 = y_trf.transform(dL.intervaly)
xr = 1.05 * (x1 - x0)
yr = 1.05 * (y1 - y0)

Expand Down Expand Up @@ -1544,12 +1542,12 @@ def apply_aspect(self, position=None):
yc = 0.5 * (ymin + ymax)
y0 = yc - Ysize / 2.0
y1 = yc + Ysize / 2.0
self.set_ybound(*map(y_trf.inverted().transform, (y0, y1)))
self.set_ybound(y_trf.inverted().transform([y0, y1]))
else:
xc = 0.5 * (xmin + xmax)
x0 = xc - Xsize / 2.0
x1 = xc + Xsize / 2.0
self.set_xbound(*map(x_trf.inverted().transform, (x0, x1)))
self.set_xbound(x_trf.inverted().transform([x0, x1]))

def axis(self, *args, emit=True, **kwargs):
"""
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6554,9 +6554,10 @@ def test_aspect_nonlinear_adjustable_datalim():

ax = fig.add_axes([.1, .1, .8, .8]) # Square.
ax.plot([.4, .6], [.4, .6]) # Set minpos to keep logit happy.
ax.set(xscale="log", xlim=(1, 10),
yscale="logit", ylim=(1/11, 1/1001),
ax.set(xscale="log", xlim=(1, 100),
yscale="logit", ylim=(1 / 101, 1 / 11),
aspect=1, adjustable="datalim")
ax.margins(0)
ax.apply_aspect()
assert ax.get_xlim() == pytest.approx(np.array([1/10, 10]) * np.sqrt(10))
assert ax.get_xlim() == pytest.approx([1*10**(1/2), 100/10**(1/2)])
assert ax.get_ylim() == (1 / 101, 1 / 11)