Skip to content

Commit ac439c8

Browse files
Code review updates
1 parent cb3f9fd commit ac439c8

1 file changed

Lines changed: 34 additions & 25 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,46 +3027,42 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
30273027
if tight is not None:
30283028
self._tight = bool(tight)
30293029

3030-
x_shared = self._shared_axes["x"].get_siblings(self)
3031-
y_shared = self._shared_axes["y"].get_siblings(self)
3030+
x_shared_axes = self._shared_axes["x"].get_siblings(self)
3031+
y_shared_axes = self._shared_axes["y"].get_siblings(self)
30323032

30333033
x_stickies = y_stickies = np.array([])
30343034
if self.use_sticky_edges:
3035-
# Use ._children and ._sticky_edges directly, because most extra
3036-
# artists in .get_children() (spines, titles, etc.) never have
3037-
# sticky edges. We also check axis objects since they can have
3038-
# sticky edges (e.g. polar RadialAxis).
30393035
if self._xmargin and scalex and self.get_autoscalex_on():
3040-
x_sticky_lists = []
3041-
for ax in x_shared:
3042-
for artist in (*ax._children, *ax._axis_map.values()):
3036+
x_sticky = []
3037+
for ax in x_shared_axes:
3038+
for artist in ax._get_data_children():
30433039
sticky_edges = artist._sticky_edges
30443040
if sticky_edges is not None and sticky_edges.x:
3045-
x_sticky_lists.append(sticky_edges.x)
3046-
if x_sticky_lists:
3047-
x_stickies = np.sort(np.concatenate(x_sticky_lists))
3041+
x_sticky.extend(sticky_edges.x)
3042+
if x_sticky:
3043+
x_stickies = np.sort(x_sticky)
30483044
if self._ymargin and scaley and self.get_autoscaley_on():
3049-
y_sticky_lists = []
3050-
for ax in y_shared:
3051-
for artist in (*ax._children, *ax._axis_map.values()):
3045+
y_sticky = []
3046+
for ax in y_shared_axes:
3047+
for artist in ax._get_data_children():
30523048
sticky_edges = artist._sticky_edges
30533049
if sticky_edges is not None and sticky_edges.y:
3054-
y_sticky_lists.append(sticky_edges.y)
3055-
if y_sticky_lists:
3056-
y_stickies = np.sort(np.concatenate(y_sticky_lists))
3050+
y_sticky.extend(sticky_edges.y)
3051+
if y_sticky:
3052+
y_stickies = np.sort(y_sticky)
30573053
if self.get_xscale() == 'log':
30583054
x_stickies = x_stickies[x_stickies > 0]
30593055
if self.get_yscale() == 'log':
30603056
y_stickies = y_stickies[y_stickies > 0]
30613057

30623058
def handle_single_axis(
3063-
scale, shared, name, axis, margin, stickies, set_bound):
3059+
scale, shared_axes, name, axis, margin, stickies, set_bound):
30643060

30653061
if not (scale and axis._get_autoscale_on()):
30663062
return # nothing to do...
30673063
# Base autoscaling on finite data limits when there is at least one
30683064
# finite data limit among all the shared_axes and intervals.
3069-
values = [val for ax in shared
3065+
values = [val for ax in shared_axes
30703066
for val in getattr(ax.dataLim, f"interval{name}")
30713067
if np.isfinite(val)]
30723068
if values:
@@ -3082,13 +3078,14 @@ def handle_single_axis(
30823078
x0, x1 = locator.nonsingular(x0, x1)
30833079
# Find the minimum minpos for use in the margin calculation.
30843080
minimum_minpos = min(
3085-
getattr(ax.dataLim, f"minpos{name}") for ax in shared)
3081+
getattr(ax.dataLim, f"minpos{name}") for ax in shared_axes)
30863082

30873083
# Prevent margin addition from crossing a sticky value. A small
30883084
# tolerance must be added due to floating point issues with
30893085
# streamplot; it is defined relative to x1-x0 but has
30903086
# no absolute term (e.g. "+1e-8") to avoid issues when working with
30913087
# datasets where all values are tiny (less than 1e-8).
3088+
x0bound = x1bound = None
30923089
if len(stickies):
30933090
tol = 1e-5 * abs(x1 - x0)
30943091
# Index of largest element < x0 + tol, if any.
@@ -3097,8 +3094,6 @@ def handle_single_axis(
30973094
# Index of smallest element > x1 - tol, if any.
30983095
i1 = stickies.searchsorted(x1 - tol)
30993096
x1bound = stickies[i1] if i1 != len(stickies) else None
3100-
else:
3101-
x0bound = x1bound = None
31023097

31033098
# Add the margin in figure space and then transform back, to handle
31043099
# non-linear scales.
@@ -3123,10 +3118,10 @@ def handle_single_axis(
31233118
# End of definition of internal function 'handle_single_axis'.
31243119

31253120
handle_single_axis(
3126-
scalex, x_shared, 'x', self.xaxis, self._xmargin,
3121+
scalex, x_shared_axes, 'x', self.xaxis, self._xmargin,
31273122
x_stickies, self.set_xbound)
31283123
handle_single_axis(
3129-
scaley, y_shared, 'y', self.yaxis, self._ymargin,
3124+
scaley, y_shared_axes, 'y', self.yaxis, self._ymargin,
31303125
y_stickies, self.set_ybound)
31313126

31323127
def _update_title_position(self, renderer):
@@ -4529,6 +4524,20 @@ def drag_pan(self, button, key, x, y):
45294524
self.set_xlim(points[:, 0])
45304525
self.set_ylim(points[:, 1])
45314526

4527+
def _get_data_children(self):
4528+
"""
4529+
Return artists that represent data (plot lines, collections, images,
4530+
patches, etc.) as opposed to auxiliary artists needed to draw the
4531+
Axes itself (spines, titles, axis objects, etc.).
4532+
4533+
Data children are the artists that can contribute to autoscaling
4534+
and sticky edges.
4535+
4536+
Note: This is a preliminary definition and has not been thought
4537+
through completely. We may want to revise this later.
4538+
"""
4539+
return [*self._children, *self._axis_map.values()]
4540+
45324541
def get_children(self):
45334542
# docstring inherited.
45344543
return [

0 commit comments

Comments
 (0)