@@ -559,6 +559,8 @@ class _AxesBase(martist.Artist):
559
559
_shared_axes = {name : cbook .Grouper () for name in _axis_names }
560
560
_twinned_axes = cbook .Grouper ()
561
561
562
+ _subclass_uses_cla = False
563
+
562
564
@property
563
565
def _axis_map (self ):
564
566
"""A mapping of axis names, e.g. 'x', to `Axis` instances."""
@@ -699,6 +701,20 @@ def __init__(self, fig, rect,
699
701
rcParams ['ytick.major.right' ]),
700
702
which = 'major' )
701
703
704
+ def __init_subclass__ (cls , ** kwargs ):
705
+ parent_uses_cla = super (cls , cls )._subclass_uses_cla
706
+ if 'cla' in cls .__dict__ :
707
+ _api .warn_deprecated (
708
+ '3.6' ,
709
+ pending = True ,
710
+ message = f'Overriding `Axes.cla` in { cls .__qualname__ } is '
711
+ 'pending deprecation in %(since)s and will be fully '
712
+ 'deprecated in favor of `Axes.clear` in the future. '
713
+ 'Please report '
714
+ f'this to the { cls .__module__ !r} author.' )
715
+ cls ._subclass_uses_cla = 'cla' in cls .__dict__ or parent_uses_cla
716
+ super ().__init_subclass__ (** kwargs )
717
+
702
718
def __getstate__ (self ):
703
719
state = super ().__getstate__ ()
704
720
# Prune the sharing & twinning info to only contain the current group.
@@ -1199,9 +1215,12 @@ def sharey(self, other):
1199
1215
self .set_ylim (y0 , y1 , emit = False , auto = other .get_autoscaley_on ())
1200
1216
self .yaxis ._scale = other .yaxis ._scale
1201
1217
1202
- def clear (self ):
1218
+ def __clear (self ):
1203
1219
"""Clear the Axes."""
1204
- # Note: this is called by Axes.__init__()
1220
+ # The actual implementation of clear() as long as clear() has to be
1221
+ # an adapter delegating to the correct implementation.
1222
+ # The implementation can move back into clear() when the
1223
+ # deprecation on cla() subclassing expires.
1205
1224
1206
1225
# stash the current visibility state
1207
1226
if hasattr (self , 'patch' ):
@@ -1318,6 +1337,24 @@ def clear(self):
1318
1337
1319
1338
self .stale = True
1320
1339
1340
+ def clear (self ):
1341
+ """Clear the Axes."""
1342
+ # Act as an alias, or as the superclass implementation depending on the
1343
+ # subclass implementation.
1344
+ if self ._subclass_uses_cla :
1345
+ self .cla ()
1346
+ else :
1347
+ self .__clear ()
1348
+
1349
+ def cla (self ):
1350
+ """Clear the Axes."""
1351
+ # Act as an alias, or as the superclass implementation depending on the
1352
+ # subclass implementation.
1353
+ if self ._subclass_uses_cla :
1354
+ self .__clear ()
1355
+ else :
1356
+ self .clear ()
1357
+
1321
1358
class ArtistList (MutableSequence ):
1322
1359
"""
1323
1360
A sublist of Axes children based on their type.
@@ -1481,10 +1518,6 @@ def texts(self):
1481
1518
return self .ArtistList (self , 'texts' , 'add_artist' ,
1482
1519
valid_types = mtext .Text )
1483
1520
1484
- def cla (self ):
1485
- """Clear the Axes."""
1486
- self .clear ()
1487
-
1488
1521
def get_facecolor (self ):
1489
1522
"""Get the facecolor of the Axes."""
1490
1523
return self .patch .get_facecolor ()
0 commit comments