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

Skip to content

Commit ca433ff

Browse files
Code review updates
1 parent 6ac6386 commit ca433ff

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,46 +3011,42 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
30113011
if tight is not None:
30123012
self._tight = bool(tight)
30133013

3014-
x_shared = self._shared_axes["x"].get_siblings(self)
3015-
y_shared = self._shared_axes["y"].get_siblings(self)
3014+
x_shared_axes = self._shared_axes["x"].get_siblings(self)
3015+
y_shared_axes = self._shared_axes["y"].get_siblings(self)
30163016

30173017
x_stickies = y_stickies = np.array([])
30183018
if self.use_sticky_edges:
3019-
# Use ._children and ._sticky_edges directly, because most extra
3020-
# artists in .get_children() (spines, titles, etc.) never have
3021-
# sticky edges. We also check axis objects since they can have
3022-
# sticky edges (e.g. polar RadialAxis).
30233019
if self._xmargin and scalex and self.get_autoscalex_on():
3024-
x_sticky_lists = []
3025-
for ax in x_shared:
3026-
for artist in (*ax._children, *ax._axis_map.values()):
3020+
x_sticky = []
3021+
for ax in x_shared_axes:
3022+
for artist in ax._get_data_children():
30273023
sticky_edges = artist._sticky_edges
30283024
if sticky_edges is not None and sticky_edges.x:
3029-
x_sticky_lists.append(sticky_edges.x)
3030-
if x_sticky_lists:
3031-
x_stickies = np.sort(np.concatenate(x_sticky_lists))
3025+
x_sticky.extend(sticky_edges.x)
3026+
if x_sticky:
3027+
x_stickies = np.sort(x_sticky)
30323028
if self._ymargin and scaley and self.get_autoscaley_on():
3033-
y_sticky_lists = []
3034-
for ax in y_shared:
3035-
for artist in (*ax._children, *ax._axis_map.values()):
3029+
y_sticky = []
3030+
for ax in y_shared_axes:
3031+
for artist in ax._get_data_children():
30363032
sticky_edges = artist._sticky_edges
30373033
if sticky_edges is not None and sticky_edges.y:
3038-
y_sticky_lists.append(sticky_edges.y)
3039-
if y_sticky_lists:
3040-
y_stickies = np.sort(np.concatenate(y_sticky_lists))
3034+
y_sticky.extend(sticky_edges.y)
3035+
if y_sticky:
3036+
y_stickies = np.sort(y_sticky)
30413037
if self.get_xscale() == 'log':
30423038
x_stickies = x_stickies[x_stickies > 0]
30433039
if self.get_yscale() == 'log':
30443040
y_stickies = y_stickies[y_stickies > 0]
30453041

30463042
def handle_single_axis(
3047-
scale, shared, name, axis, margin, stickies, set_bound):
3043+
scale, shared_axes, name, axis, margin, stickies, set_bound):
30483044

30493045
if not (scale and axis._get_autoscale_on()):
30503046
return # nothing to do...
30513047
# Base autoscaling on finite data limits when there is at least one
30523048
# finite data limit among all the shared_axes and intervals.
3053-
values = [val for ax in shared
3049+
values = [val for ax in shared_axes
30543050
for val in getattr(ax.dataLim, f"interval{name}")
30553051
if np.isfinite(val)]
30563052
if values:
@@ -3066,7 +3062,7 @@ def handle_single_axis(
30663062
x0, x1 = locator.nonsingular(x0, x1)
30673063
# Find the minimum minpos for use in the margin calculation.
30683064
minimum_minpos = min(
3069-
getattr(ax.dataLim, f"minpos{name}") for ax in shared)
3065+
getattr(ax.dataLim, f"minpos{name}") for ax in shared_axes)
30703066

30713067
# Prevent margin addition from crossing a sticky value. A small
30723068
# tolerance must be added due to floating point issues with
@@ -3107,10 +3103,10 @@ def handle_single_axis(
31073103
# End of definition of internal function 'handle_single_axis'.
31083104

31093105
handle_single_axis(
3110-
scalex, x_shared, 'x', self.xaxis, self._xmargin,
3106+
scalex, x_shared_axes, 'x', self.xaxis, self._xmargin,
31113107
x_stickies, self.set_xbound)
31123108
handle_single_axis(
3113-
scaley, y_shared, 'y', self.yaxis, self._ymargin,
3109+
scaley, y_shared_axes, 'y', self.yaxis, self._ymargin,
31143110
y_stickies, self.set_ybound)
31153111

31163112
def _update_title_position(self, renderer):
@@ -4513,6 +4509,17 @@ def drag_pan(self, button, key, x, y):
45134509
self.set_xlim(points[:, 0])
45144510
self.set_ylim(points[:, 1])
45154511

4512+
def _get_data_children(self):
4513+
"""
4514+
Return artists that represent data (plot lines, collections, images,
4515+
patches, etc.) as opposed to auxiliary artists needed to draw the
4516+
Axes itself (spines, titles, axis objects, etc.).
4517+
4518+
Data children are the artists that can contribute to autoscaling
4519+
and sticky edges.
4520+
"""
4521+
return [*self._children, *self._axis_map.values()]
4522+
45164523
def get_children(self):
45174524
# docstring inherited.
45184525
return [

0 commit comments

Comments
 (0)