Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cc3d8b4

Browse filesBrowse files
committed
Move Axes.lines into a hidden children attribute.
The lines can still be accessed via a read-only property.
1 parent 421d7b3 commit cc3d8b4
Copy full SHA for cc3d8b4

File tree

Expand file treeCollapse file tree

3 files changed

+23
-19
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-19
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,9 @@ def _to_points(xy1, xy2, slope):
10021002
if line.get_clip_path() is None:
10031003
line.set_clip_path(self.patch)
10041004
if not line.get_label():
1005-
line.set_label(f"_line{len(self.lines)}")
1006-
self.lines.append(line)
1007-
line._remove_method = self.lines.remove
1005+
line.set_label(f"_line{len(self._children)}")
1006+
self._children.append(line)
1007+
line._remove_method = self._children.remove
10081008
self.update_datalim(datalim)
10091009

10101010
self._request_autoscale_view()

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+16-12Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def _update_transScale(self):
859859
self.transScale.set(
860860
mtransforms.blended_transform_factory(
861861
self.xaxis.get_transform(), self.yaxis.get_transform()))
862-
for line in getattr(self, "lines", []): # Not set during init.
862+
for line in getattr(self, "_children", []): # Not set during init.
863863
try:
864864
line._transformed_path.invalidate()
865865
except AttributeError:
@@ -1102,7 +1102,7 @@ def cla(self):
11021102
self._get_patches_for_fill = _process_plot_var_args(self, 'fill')
11031103

11041104
self._gridOn = mpl.rcParams['axes.grid']
1105-
self.lines = []
1105+
self._children = []
11061106
self.patches = []
11071107
self.texts = []
11081108
self.tables = []
@@ -1180,6 +1180,10 @@ def cla(self):
11801180

11811181
self.stale = True
11821182

1183+
@property
1184+
def lines(self):
1185+
return tuple(a for a in self._children if isinstance(a, mlines.Line2D))
1186+
11831187
def clear(self):
11841188
"""Clear the axes."""
11851189
self.cla()
@@ -1967,17 +1971,17 @@ def _update_image_limits(self, image):
19671971

19681972
def add_line(self, line):
19691973
"""
1970-
Add a `.Line2D` to the axes' lines; return the line.
1974+
Add a `.Line2D` to the Axes; return the line.
19711975
"""
19721976
self._set_artist_props(line)
19731977
if line.get_clip_path() is None:
19741978
line.set_clip_path(self.patch)
19751979

19761980
self._update_line_limits(line)
19771981
if not line.get_label():
1978-
line.set_label('_line%d' % len(self.lines))
1979-
self.lines.append(line)
1980-
line._remove_method = self.lines.remove
1982+
line.set_label(f'_line{len(self._children)}')
1983+
self._children.append(line)
1984+
line._remove_method = self._children.remove
19811985
self.stale = True
19821986
return line
19831987

@@ -2510,21 +2514,21 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
25102514
x_stickies = y_stickies = np.array([])
25112515
if self.use_sticky_edges:
25122516
# Only iterate over axes and artists if needed. The check for
2513-
# ``hasattr(ax, "lines")`` is necessary because this can be called
2514-
# very early in the axes init process (e.g., for twin axes) when
2515-
# these attributes don't even exist yet, in which case
2517+
# ``hasattr(ax, "_children")`` is necessary because this can be
2518+
# called very early in the axes init process (e.g., for twin axes)
2519+
# when these attributes don't even exist yet, in which case
25162520
# `get_children` would raise an AttributeError.
25172521
if self._xmargin and scalex and self._autoscaleXon:
25182522
x_stickies = np.sort(np.concatenate([
25192523
artist.sticky_edges.x
25202524
for ax in self._shared_x_axes.get_siblings(self)
2521-
if hasattr(ax, "lines")
2525+
if hasattr(ax, "_children")
25222526
for artist in ax.get_children()]))
25232527
if self._ymargin and scaley and self._autoscaleYon:
25242528
y_stickies = np.sort(np.concatenate([
25252529
artist.sticky_edges.y
25262530
for ax in self._shared_y_axes.get_siblings(self)
2527-
if hasattr(ax, "lines")
2531+
if hasattr(ax, "_children")
25282532
for artist in ax.get_children()]))
25292533
if self.get_xscale().lower() == 'log':
25302534
x_stickies = x_stickies[x_stickies > 0]
@@ -4056,7 +4060,7 @@ def get_children(self):
40564060
return [
40574061
*self.collections,
40584062
*self.patches,
4059-
*self.lines,
4063+
*self._children,
40604064
*self.texts,
40614065
*self.artists,
40624066
*self.spines.values(),

‎lib/matplotlib/legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,13 +1119,13 @@ def _get_legend_handles(axs, legend_handler_map=None):
11191119
"""
11201120
handles_original = []
11211121
for ax in axs:
1122-
handles_original += (ax.lines + ax.patches +
1123-
ax.collections + ax.containers)
1122+
handles_original += [*ax.lines, *ax.patches, *ax.collections,
1123+
*ax.containers]
11241124
# support parasite axes:
11251125
if hasattr(ax, 'parasites'):
11261126
for axx in ax.parasites:
1127-
handles_original += (axx.lines + axx.patches +
1128-
axx.collections + axx.containers)
1127+
handles_original += [*axx.lines, *axx.patches,
1128+
*axx.collections, *axx.containers]
11291129

11301130
handler_map = Legend.get_default_handler_map()
11311131

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.