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

Skip to content

Commit 3aecf00

Browse files
committed
Reduce the data limit logic some more
1 parent 1718f34 commit 3aecf00

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,20 +2539,19 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
25392539
return # nothing to do...
25402540

25412541
shared = shared_axes.get_siblings(self)
2542-
dl = [ax.dataLim for ax in shared]
2543-
# ignore non-finite data limits if good limits exist
2544-
# issue 18137: The previous code would allow one subplot with
2545-
# inifinite data limits to 'clobber' other subplots with finite
2546-
# data limits.
2542+
# Base autoscaling on finite data limits when there is at least one
2543+
# finite data limit among all the shared_axes and intervals.
2544+
# Also, find the minimum minpos for use in the margin calculation.
25472545
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()
2553-
finite_x_values = np.extract(np.isfinite(x_values), x_values)
2554-
if finite_x_values.size >= 1:
2555-
x0, x1 = (finite_x_values.min(), finite_x_values.max())
2546+
minimum_minpos = np.inf
2547+
for ax in shared:
2548+
x_values.extend(getattr(ax.dataLim, interval))
2549+
minimum_minpos = np.min(
2550+
[minimum_minpos, getattr(ax.dataLim, minpos)]
2551+
)
2552+
x_values = np.extract(np.isfinite(x_values), x_values)
2553+
if x_values.size >= 1:
2554+
x0, x1 = (x_values.min(), x_values.max())
25562555
else:
25572556
x0, x1 = (-np.inf, np.inf)
25582557
# If x0 and x1 are non finite, use the locator to figure out
@@ -2575,10 +2574,9 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
25752574

25762575
# Add the margin in figure space and then transform back, to handle
25772576
# non-linear scales.
2578-
minpos = np.min(minpos_values)
25792577
transform = axis.get_transform()
25802578
inverse_trans = transform.inverted()
2581-
x0, x1 = axis._scale.limit_range_for_scale(x0, x1, minpos)
2579+
x0, x1 = axis._scale.limit_range_for_scale(x0, x1, minimum_minpos)
25822580
x0t, x1t = transform.transform([x0, x1])
25832581
delta = (x1t - x0t) * margin
25842582
if not np.isfinite(delta):

0 commit comments

Comments
 (0)