Skip to content

Commit 5bbd7a1

Browse files
Speed up sticky edges handling
fix get_children
1 parent a847da9 commit 5bbd7a1

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,32 +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)
3032+
30303033
x_stickies = y_stickies = np.array([])
30313034
if self.use_sticky_edges:
30323035
if self._xmargin and scalex and self.get_autoscalex_on():
3033-
edges = []
3034-
for ax in self._shared_axes["x"].get_siblings(self):
3036+
# Use ._children and ._sticky_edges directly, because the extra
3037+
# artists in .get_children() (spines, axes, titles, etc.) never
3038+
# have sticky edges, so we can skip them for performance.
3039+
x_sticky_lists = []
3040+
for ax in x_shared:
30353041
for artist in ax.get_children():
3036-
edges.extend(artist.sticky_edges.x)
3037-
x_stickies = np.sort(edges)
3042+
sticky_edges = artist._sticky_edges
3043+
if sticky_edges is not None and sticky_edges.x:
3044+
x_sticky_lists.append(sticky_edges.x)
3045+
if x_sticky_lists:
3046+
x_stickies = np.sort(np.concatenate(x_sticky_lists))
30383047
if self._ymargin and scaley and self.get_autoscaley_on():
3039-
edges = []
3040-
for ax in self._shared_axes["y"].get_siblings(self):
3048+
y_sticky_lists = []
3049+
for ax in y_shared:
30413050
for artist in ax.get_children():
3042-
edges.extend(artist.sticky_edges.y)
3043-
y_stickies = np.sort(edges)
3051+
sticky_edges = artist._sticky_edges
3052+
if sticky_edges is not None and sticky_edges.y:
3053+
y_sticky_lists.append(sticky_edges.y)
3054+
if y_sticky_lists:
3055+
y_stickies = np.sort(np.concatenate(y_sticky_lists))
30443056
if self.get_xscale() == 'log':
30453057
x_stickies = x_stickies[x_stickies > 0]
30463058
if self.get_yscale() == 'log':
30473059
y_stickies = y_stickies[y_stickies > 0]
30483060

30493061
def handle_single_axis(
3050-
scale, shared_axes, name, axis, margin, stickies, set_bound):
3062+
scale, shared, name, axis, margin, stickies, set_bound):
30513063

30523064
if not (scale and axis._get_autoscale_on()):
30533065
return # nothing to do...
3054-
3055-
shared = shared_axes.get_siblings(self)
30563066
# Base autoscaling on finite data limits when there is at least one
30573067
# finite data limit among all the shared_axes and intervals.
30583068
values = [val for ax in shared
@@ -3109,10 +3119,10 @@ def handle_single_axis(
31093119
# End of definition of internal function 'handle_single_axis'.
31103120

31113121
handle_single_axis(
3112-
scalex, self._shared_axes["x"], 'x', self.xaxis, self._xmargin,
3122+
scalex, x_shared, 'x', self.xaxis, self._xmargin,
31133123
x_stickies, self.set_xbound)
31143124
handle_single_axis(
3115-
scaley, self._shared_axes["y"], 'y', self.yaxis, self._ymargin,
3125+
scaley, y_shared, 'y', self.yaxis, self._ymargin,
31163126
y_stickies, self.set_ybound)
31173127

31183128
def _update_title_position(self, renderer):

0 commit comments

Comments
 (0)