(
scale, shared_axes, name, axis, margin, stickies, set_bound)
| 3143 | y_stickies = y_stickies[y_stickies > 0] |
| 3144 | |
| 3145 | def handle_single_axis( |
| 3146 | scale, shared_axes, name, axis, margin, stickies, set_bound): |
| 3147 | |
| 3148 | if not (scale and axis._get_autoscale_on()): |
| 3149 | return # nothing to do... |
| 3150 | # Base autoscaling on finite data limits when there is at least one |
| 3151 | # finite data limit among all the shared_axes and intervals. |
| 3152 | values = [val for ax in shared_axes |
| 3153 | for val in getattr(ax.dataLim, f"interval{name}") |
| 3154 | if np.isfinite(val)] |
| 3155 | if values: |
| 3156 | x0, x1 = (min(values), max(values)) |
| 3157 | elif getattr(self._viewLim, f"mutated{name}")(): |
| 3158 | # No data, but explicit viewLims already set: |
| 3159 | # in mutatedx or mutatedy. |
| 3160 | return |
| 3161 | else: |
| 3162 | x0, x1 = (-np.inf, np.inf) |
| 3163 | # If x0 and x1 are nonfinite, get default limits from the locator. |
| 3164 | locator = axis.get_major_locator() |
| 3165 | x0, x1 = locator.nonsingular(x0, x1) |
| 3166 | # Find the minimum minpos for use in the margin calculation. |
| 3167 | minimum_minpos = min( |
| 3168 | getattr(ax.dataLim, f"minpos{name}") for ax in shared_axes) |
| 3169 | |
| 3170 | # Prevent margin addition from crossing a sticky value. A small |
| 3171 | # tolerance must be added due to floating point issues with |
| 3172 | # streamplot; it is defined relative to x1-x0 but has |
| 3173 | # no absolute term (e.g. "+1e-8") to avoid issues when working with |
| 3174 | # datasets where all values are tiny (less than 1e-8). |
| 3175 | x0bound = x1bound = None |
| 3176 | if len(stickies): |
| 3177 | tol = 1e-5 * abs(x1 - x0) |
| 3178 | # Index of largest element < x0 + tol, if any. |
| 3179 | i0 = stickies.searchsorted(x0 + tol) - 1 |
| 3180 | x0bound = stickies[i0] if i0 != -1 else None |
| 3181 | # Index of smallest element > x1 - tol, if any. |
| 3182 | i1 = stickies.searchsorted(x1 - tol) |
| 3183 | x1bound = stickies[i1] if i1 != len(stickies) else None |
| 3184 | |
| 3185 | # Add the margin in figure space and then transform back, to handle |
| 3186 | # non-linear scales. |
| 3187 | transform = axis.get_transform() |
| 3188 | inverse_trans = transform.inverted() |
| 3189 | x0, x1 = axis._scale.limit_range_for_scale(x0, x1, minimum_minpos) |
| 3190 | x0t, x1t = transform.transform([x0, x1]) |
| 3191 | delta = (x1t - x0t) * margin |
| 3192 | if not np.isfinite(delta): |
| 3193 | delta = 0 # If a bound isn't finite, set margin to zero. |
| 3194 | x0, x1 = inverse_trans.transform([x0t - delta, x1t + delta]) |
| 3195 | |
| 3196 | # Apply sticky bounds. |
| 3197 | if x0bound is not None: |
| 3198 | x0 = max(x0, x0bound) |
| 3199 | if x1bound is not None: |
| 3200 | x1 = min(x1, x1bound) |
| 3201 | |
| 3202 | if not self._tight: |
nothing calls this directly
no test coverage detected