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

Skip to content

Commit 5462669

Browse files
Lazily construct sticky edges
1 parent 25811a7 commit 5462669

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

lib/matplotlib/artist.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def __init__(self):
223223
self._snap = None
224224
self._sketch = mpl.rcParams['path.sketch']
225225
self._path_effects = mpl.rcParams['path.effects']
226-
self._sticky_edges = _XYPair([], [])
226+
self._sticky_edges = None
227227
self._in_layout = True
228228

229229
def __getstate__(self):
@@ -1209,6 +1209,8 @@ def sticky_edges(self):
12091209
>>> artist.sticky_edges.y[:] = (ymin, ymax)
12101210
12111211
"""
1212+
if self._sticky_edges is None:
1213+
self._sticky_edges = _XYPair([], [])
12121214
return self._sticky_edges
12131215

12141216
def update_from(self, other):
@@ -1223,8 +1225,11 @@ def update_from(self, other):
12231225
self._label = other._label
12241226
self._sketch = other._sketch
12251227
self._path_effects = other._path_effects
1226-
self.sticky_edges.x[:] = other.sticky_edges.x.copy()
1227-
self.sticky_edges.y[:] = other.sticky_edges.y.copy()
1228+
if other._sticky_edges is not None:
1229+
self.sticky_edges.x[:] = other._sticky_edges.x.copy()
1230+
self.sticky_edges.y[:] = other._sticky_edges.y.copy()
1231+
else:
1232+
self._sticky_edges = None
12281233
self.pchanged()
12291234
self.stale = True
12301235

lib/matplotlib/axes/_base.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,23 +3016,25 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
30163016

30173017
x_stickies = y_stickies = np.array([])
30183018
if self.use_sticky_edges:
3019+
# Use ._children and ._sticky_edges directly, because the extra
3020+
# artists in .get_children() (spines, axes, titles, etc.) never
3021+
# have sticky edges, so we can skip them for performance.
30193022
if self._xmargin and scalex and self.get_autoscalex_on():
3020-
# Use ._children and ._sticky_edges directly, because the extra
3021-
# artists in .get_children() (spines, axes, titles, etc.) never
3022-
# have sticky edges, so we can skip them for performance.
30233023
x_sticky_lists = []
30243024
for ax in x_shared:
30253025
for artist in ax._children:
3026-
if artist._sticky_edges.x:
3027-
x_sticky_lists.append(artist._sticky_edges.x)
3026+
sticky_edges = artist._sticky_edges
3027+
if sticky_edges is not None and sticky_edges.x:
3028+
x_sticky_lists.append(sticky_edges.x)
30283029
if x_sticky_lists:
30293030
x_stickies = np.sort(np.concatenate(x_sticky_lists))
30303031
if self._ymargin and scaley and self.get_autoscaley_on():
30313032
y_sticky_lists = []
30323033
for ax in y_shared:
30333034
for artist in ax._children:
3034-
if artist._sticky_edges.y:
3035-
y_sticky_lists.append(artist._sticky_edges.y)
3035+
sticky_edges = artist._sticky_edges
3036+
if sticky_edges is not None and sticky_edges.y:
3037+
y_sticky_lists.append(sticky_edges.y)
30363038
if y_sticky_lists:
30373039
y_stickies = np.sort(np.concatenate(y_sticky_lists))
30383040
if self.get_xscale() == 'log':

0 commit comments

Comments
 (0)