Repository: matplotlib/matplotlib
File: lib/matplotlib/axes/_base.py (Python)

Code before:
                    for artist in ax.get_children()]))
        if self.get_xscale().lower() == 'log':
            x_stickies = x_stickies[x_stickies > 0]
        if self.get_yscale().lower() == 'log':
            y_stickies = y_stickies[y_stickies > 0]

        def handle_single_axis(scale, autoscaleon, shared_axes, interval,
                               minpos, axis, margin, stickies, set_bound):

            if not (scale and autoscaleon):
                return  # nothing to do...

            shared = shared_axes.get_siblings(self)
            dl = [ax.dataLim for ax in shared]
            # ignore non-finite data limits if good limits exist
            # issue 18137: The previous code would allow one subplot with
            # inifinite data limits to 'clobber' other subplots with finite
            # data limits.
            x_values = []
            minpos_values = []
            for d in dl:
                x_values.extend(getattr(d, interval))
                minpos_values.append(getattr(d, minpos))
            x_values = np.sort(x_values).flatten()
            finite_x_values = np.extract(np.isfinite(x_values), x_values)
            if finite_x_values.size >= 1:
                x0, x1 = (finite_x_values.min(), finite_x_values.max())
            else:
                x0, x1 = (-np.inf, np.inf)
            # If x0 and x1 are non finite, use the locator to figure out
            # default limits.
            locator = axis.get_major_locator()
            x0, x1 = locator.nonsingular(x0, x1)

            # Prevent margin addition from crossing a sticky value.  A small
            # tolerance must be added due to floating point issues with
            # streamplot; it is defined relative to x0, x1, x1-x0 but has
            # no absolute term (e.g. "+1e-8") to avoid issues when working with
            # datasets where all values are tiny (less than 1e-8).
            tol = 1e-5 * max(abs(x0), abs(x1), abs(x1 - x0))
            # Index of largest element < x0 + tol, if any.
            i0 = stickies.searchsorted(x0 + tol) - 1
            x0bound = stickies[i0] if i0 != -1 else None
            # Index of smallest element > x1 - tol, if any.
            i1 = stickies.searchsorted(x1 - tol)
            x1bound = stickies[i1] if i1 != len(stickies) else None

            # Add the margin in figure space and then transform back, to handle
            # non-linear scales.
            minpos = np.min(minpos_values)
            transform = axis.get_transform()

Review comment (suggestion):
Is there a good reason to pack the array, and then flatten it, and then get the min/max versus just doing min/max inside the loop?  This just seems like a lot of packing and unpacking for stuff that can be directly accessed.  I don't see that any of these variables are used below, but I may have missed it.  

e.g.
```python
minpos = np.Inf
x0 = np.Inf
x1 = -np.Inf
for ax in shared:
   for x in ax.dataLim.interval:
      if np.isfinite(x):
         x1 = np.max(x, x1)
         x0 = np.min(x, x0)
   if np.isfinite(ax.dataLim.minpos):
       minpos = np.min(ax.dataLim.minpos, minpos)
# then a check if still infinite...

```

Code after:
                    for artist in ax.get_children()]))
        if self.get_xscale().lower() == 'log':
            x_stickies = x_stickies[x_stickies > 0]
        if self.get_yscale().lower() == 'log':
            y_stickies = y_stickies[y_stickies > 0]

        def handle_single_axis(scale, autoscaleon, shared_axes, interval,
                               minpos, axis, margin, stickies, set_bound):

            if not (scale and autoscaleon):
                return  # nothing to do...

            shared = shared_axes.get_siblings(self)
            # Base autoscaling on finite data limits when there is at least one
            # finite data limit among all the shared_axes and intervals.
            # Also, find the minimum minpos for use in the margin calculation.
            x_values = []
            minimum_minpos = np.inf
            for ax in shared:
                x_values.extend(getattr(ax.dataLim, interval))
                minimum_minpos = min(minimum_minpos,
                                     getattr(ax.dataLim, minpos))
            x_values = np.extract(np.isfinite(x_values), x_values)
            if x_values.size >= 1:
                x0, x1 = (x_values.min(), x_values.max())
            else:
                x0, x1 = (-np.inf, np.inf)
            # If x0 and x1 are non finite, use the locator to figure out
            # default limits.
            locator = axis.get_major_locator()
            x0, x1 = locator.nonsingular(x0, x1)

            # Prevent margin addition from crossing a sticky value.  A small
            # tolerance must be added due to floating point issues with
            # streamplot; it is defined relative to x0, x1, x1-x0 but has
            # no absolute term (e.g. "+1e-8") to avoid issues when working with
            # datasets where all values are tiny (less than 1e-8).
            tol = 1e-5 * max(abs(x0), abs(x1), abs(x1 - x0))
            # Index of largest element < x0 + tol, if any.
            i0 = stickies.searchsorted(x0 + tol) - 1
            x0bound = stickies[i0] if i0 != -1 else None
            # Index of smallest element > x1 - tol, if any.
            i1 = stickies.searchsorted(x1 - tol)
            x1bound = stickies[i1] if i1 != len(stickies) else None

            # Add the margin in figure space and then transform back, to handle
            # non-linear scales.
            transform = axis.get_transform()
            inverse_trans = transform.inverted()
            x0, x1 = axis._scale.limit_range_for_scale(x0, x1, minimum_minpos)
            x0t, x1t = transform.transform([x0, x1])