@@ -859,7 +859,7 @@ def _update_transScale(self):
859
859
self .transScale .set (
860
860
mtransforms .blended_transform_factory (
861
861
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.
863
863
try :
864
864
line ._transformed_path .invalidate ()
865
865
except AttributeError :
@@ -1102,7 +1102,7 @@ def cla(self):
1102
1102
self ._get_patches_for_fill = _process_plot_var_args (self , 'fill' )
1103
1103
1104
1104
self ._gridOn = mpl .rcParams ['axes.grid' ]
1105
- self .lines = []
1105
+ self ._children = []
1106
1106
self .patches = []
1107
1107
self .texts = []
1108
1108
self .tables = []
@@ -1180,6 +1180,10 @@ def cla(self):
1180
1180
1181
1181
self .stale = True
1182
1182
1183
+ @property
1184
+ def lines (self ):
1185
+ return tuple (a for a in self ._children if isinstance (a , mlines .Line2D ))
1186
+
1183
1187
def clear (self ):
1184
1188
"""Clear the axes."""
1185
1189
self .cla ()
@@ -1967,17 +1971,17 @@ def _update_image_limits(self, image):
1967
1971
1968
1972
def add_line (self , line ):
1969
1973
"""
1970
- Add a `.Line2D` to the axes' lines ; return the line.
1974
+ Add a `.Line2D` to the Axes ; return the line.
1971
1975
"""
1972
1976
self ._set_artist_props (line )
1973
1977
if line .get_clip_path () is None :
1974
1978
line .set_clip_path (self .patch )
1975
1979
1976
1980
self ._update_line_limits (line )
1977
1981
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
1981
1985
self .stale = True
1982
1986
return line
1983
1987
@@ -2510,21 +2514,21 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
2510
2514
x_stickies = y_stickies = np .array ([])
2511
2515
if self .use_sticky_edges :
2512
2516
# 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
2516
2520
# `get_children` would raise an AttributeError.
2517
2521
if self ._xmargin and scalex and self ._autoscaleXon :
2518
2522
x_stickies = np .sort (np .concatenate ([
2519
2523
artist .sticky_edges .x
2520
2524
for ax in self ._shared_x_axes .get_siblings (self )
2521
- if hasattr (ax , "lines " )
2525
+ if hasattr (ax , "_children " )
2522
2526
for artist in ax .get_children ()]))
2523
2527
if self ._ymargin and scaley and self ._autoscaleYon :
2524
2528
y_stickies = np .sort (np .concatenate ([
2525
2529
artist .sticky_edges .y
2526
2530
for ax in self ._shared_y_axes .get_siblings (self )
2527
- if hasattr (ax , "lines " )
2531
+ if hasattr (ax , "_children " )
2528
2532
for artist in ax .get_children ()]))
2529
2533
if self .get_xscale ().lower () == 'log' :
2530
2534
x_stickies = x_stickies [x_stickies > 0 ]
@@ -4056,7 +4060,7 @@ def get_children(self):
4056
4060
return [
4057
4061
* self .collections ,
4058
4062
* self .patches ,
4059
- * self .lines ,
4063
+ * self ._children ,
4060
4064
* self .texts ,
4061
4065
* self .artists ,
4062
4066
* self .spines .values (),
0 commit comments