Skip to content

Commit 8810536

Browse files
committed
Init axes._children early enough to avoid need for some getattr calls.
1 parent ccbd641 commit 8810536

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ def __init__(self, fig,
665665
self.set_box_aspect(box_aspect)
666666
self._axes_locator = None # Optionally set via update(kwargs).
667667

668+
self._children = []
669+
668670
# placeholder for any colorbars added that use this Axes.
669671
# (see colorbar.py):
670672
self._colorbars = []
@@ -1078,7 +1080,7 @@ def _update_transScale(self):
10781080
self.transScale.set(
10791081
mtransforms.blended_transform_factory(
10801082
self.xaxis.get_transform(), self.yaxis.get_transform()))
1081-
for line in getattr(self, "_children", []): # Not set during init.
1083+
for line in self._children:
10821084
if not isinstance(line, mlines.Line2D):
10831085
continue
10841086
try:
@@ -2936,22 +2938,15 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
29362938

29372939
x_stickies = y_stickies = np.array([])
29382940
if self.use_sticky_edges:
2939-
# Only iterate over Axes and artists if needed. The check for
2940-
# ``hasattr(ax, "_children")`` is necessary because this can be
2941-
# called very early in the Axes init process (e.g., for twin Axes)
2942-
# when these attributes don't even exist yet, in which case
2943-
# `get_children` would raise an AttributeError.
29442941
if self._xmargin and scalex and self.get_autoscalex_on():
29452942
x_stickies = np.sort(np.concatenate([
29462943
artist.sticky_edges.x
29472944
for ax in self._shared_axes["x"].get_siblings(self)
2948-
if hasattr(ax, "_children")
29492945
for artist in ax.get_children()]))
29502946
if self._ymargin and scaley and self.get_autoscaley_on():
29512947
y_stickies = np.sort(np.concatenate([
29522948
artist.sticky_edges.y
29532949
for ax in self._shared_axes["y"].get_siblings(self)
2954-
if hasattr(ax, "_children")
29552950
for artist in ax.get_children()]))
29562951
if self.get_xscale() == 'log':
29572952
x_stickies = x_stickies[x_stickies > 0]

0 commit comments

Comments
 (0)