Skip to content

Commit 1718f34

Browse files
committed
Improve finite data limit algorithm efficiency
1 parent 8896d90 commit 1718f34

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,27 +2541,15 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
25412541
shared = shared_axes.get_siblings(self)
25422542
dl = [ax.dataLim for ax in shared]
25432543
# ignore non-finite data limits if good limits exist
2544-
finite_dl = [d for d in dl if np.isfinite(d).all()]
2545-
if len(finite_dl):
2546-
# if finite limits exist for at least one axis (and the
2547-
# other is infinite), restore the finite limits
2548-
x_finite = [d for d in dl
2549-
if (np.isfinite(d.intervalx).all() and
2550-
(d not in finite_dl))]
2551-
y_finite = [d for d in dl
2552-
if (np.isfinite(d.intervaly).all() and
2553-
(d not in finite_dl))]
2554-
2555-
dl = finite_dl
2556-
dl.extend(x_finite)
2557-
dl.extend(y_finite)
2558-
2559-
bb = mtransforms.BboxBase.union(dl)
2560-
# Issue 18137
2561-
# bb can still have infinite limits, so instead compute
2562-
# finite limits for this 'axis'
2563-
x_values = [getattr(d, interval) for d in dl]
2564-
x_values = np.sort(np.unique(np.asarray(x_values).flatten()))
2544+
# issue 18137: The previous code would allow one subplot with
2545+
# inifinite data limits to 'clobber' other subplots with finite
2546+
# data limits.
2547+
x_values = []
2548+
minpos_values = []
2549+
for d in dl:
2550+
x_values.extend(getattr(d, interval))
2551+
minpos_values.append(getattr(d, minpos))
2552+
x_values = np.sort(x_values).flatten()
25652553
finite_x_values = np.extract(np.isfinite(x_values), x_values)
25662554
if finite_x_values.size >= 1:
25672555
x0, x1 = (finite_x_values.min(), finite_x_values.max())
@@ -2587,7 +2575,7 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
25872575

25882576
# Add the margin in figure space and then transform back, to handle
25892577
# non-linear scales.
2590-
minpos = getattr(bb, minpos)
2578+
minpos = np.min(minpos_values)
25912579
transform = axis.get_transform()
25922580
inverse_trans = transform.inverted()
25932581
x0, x1 = axis._scale.limit_range_for_scale(x0, x1, minpos)

0 commit comments

Comments
 (0)