Skip to content

Commit 65b3586

Browse files
authored
Merge pull request #18710 from timhoffm/deprecate-cla
Deprecate cla() methods of Axis and Spines in favor of clear()
2 parents eaf4558 + f13cc98 commit 65b3586

File tree

9 files changed

+49
-17
lines changed

9 files changed

+49
-17
lines changed

doc/api/axis_api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Inheritance
4040
:template: autosummary.rst
4141
:nosignatures:
4242

43+
Axis.clear
4344
Axis.cla
4445
Axis.get_scale
4546

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``Axis.cla()``, ``RadialAxis.cla()``, ``ThetaAxis.cla()`` and ``Spine.cla()``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
These methods are deprecated in favor of the respective ``clear()`` methods.

examples/misc/custom_projection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _init_axis(self):
4848
self.xaxis = maxis.XAxis(self)
4949
self.yaxis = maxis.YAxis(self)
5050
# Do not register xaxis or yaxis with spines -- as done in
51-
# Axes._init_axis() -- until GeoAxes.xaxis.cla() works.
51+
# Axes._init_axis() -- until GeoAxes.xaxis.clear() works.
5252
# self.spines['geo'].register_axis(self.yaxis)
5353
self._update_transScale()
5454

lib/matplotlib/axes/_base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1100,11 +1100,11 @@ def cla(self):
11001100
xaxis_visible = self.xaxis.get_visible()
11011101
yaxis_visible = self.yaxis.get_visible()
11021102

1103-
self.xaxis.cla()
1104-
self.yaxis.cla()
1103+
self.xaxis.clear()
1104+
self.yaxis.clear()
11051105

11061106
for name, spine in self.spines.items():
1107-
spine.cla()
1107+
spine.clear()
11081108

11091109
self.ignore_existing_data_limits = True
11101110
self.callbacks = cbook.CallbackRegistry()

lib/matplotlib/axis.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ def __init__(self, axes, pickradius=15):
705705
self._major_tick_kw = dict()
706706
self._minor_tick_kw = dict()
707707

708-
self.cla()
708+
self.clear()
709709
self._set_scale('linear')
710710

711711
# During initialization, Axis objects often create ticks that are later
@@ -768,8 +768,19 @@ def get_children(self):
768768
return [self.label, self.offsetText,
769769
*self.get_major_ticks(), *self.get_minor_ticks()]
770770

771-
def cla(self):
772-
"""Clear this axis."""
771+
def clear(self):
772+
"""
773+
Clear the axis.
774+
775+
This resets axis properties to their default values:
776+
777+
- the label
778+
- the scale
779+
- locators, formatters and ticks
780+
- major and minor grid
781+
- units
782+
- registered callbacks
783+
"""
773784

774785
self.label.set_text('') # self.set_label_text would change isDefault_
775786

@@ -793,6 +804,11 @@ def cla(self):
793804
self.set_units(None)
794805
self.stale = True
795806

807+
@cbook.deprecated("3.4", alternative="Axis.clear()")
808+
def cla(self):
809+
"""Clear this axis."""
810+
return self.clear()
811+
796812
def reset_ticks(self):
797813
"""
798814
Re-initialize the major and minor Tick lists.

lib/matplotlib/projections/geo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _init_axis(self):
3232
self.xaxis = maxis.XAxis(self)
3333
self.yaxis = maxis.YAxis(self)
3434
# Do not register xaxis or yaxis with spines -- as done in
35-
# Axes._init_axis() -- until GeoAxes.xaxis.cla() works.
35+
# Axes._init_axis() -- until GeoAxes.xaxis.clear() works.
3636
# self.spines['geo'].register_axis(self.yaxis)
3737
self._update_transScale()
3838

lib/matplotlib/projections/polar.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,15 @@ def _wrap_locator_formatter(self):
378378
self.isDefault_majloc = True
379379
self.isDefault_majfmt = True
380380

381-
def cla(self):
382-
super().cla()
381+
def clear(self):
382+
super().clear()
383383
self.set_ticks_position('none')
384384
self._wrap_locator_formatter()
385385

386+
@cbook.deprecated("3.4", alternative="ThetaAxis.clear()")
387+
def cla(self):
388+
self.clear()
389+
386390
def _set_scale(self, value, **kwargs):
387391
super()._set_scale(value, **kwargs)
388392
self._wrap_locator_formatter()
@@ -680,11 +684,15 @@ def _wrap_locator_formatter(self):
680684
self.axes))
681685
self.isDefault_majloc = True
682686

683-
def cla(self):
684-
super().cla()
687+
def clear(self):
688+
super().clear()
685689
self.set_ticks_position('none')
686690
self._wrap_locator_formatter()
687691

692+
@cbook.deprecated("3.4", alternative="RadialAxis.clear()")
693+
def cla(self):
694+
self.clear()
695+
688696
def _set_scale(self, value, **kwargs):
689697
super()._set_scale(value, **kwargs)
690698
self._wrap_locator_formatter()
@@ -810,7 +818,7 @@ def _init_axis(self):
810818
# This is moved out of __init__ because non-separable axes don't use it
811819
self.xaxis = ThetaAxis(self)
812820
self.yaxis = RadialAxis(self)
813-
# Calling polar_axes.xaxis.cla() or polar_axes.xaxis.cla()
821+
# Calling polar_axes.xaxis.clear() or polar_axes.xaxis.clear()
814822
# results in weird artifacts. Therefore we disable this for
815823
# now.
816824
# self.spines['polar'].register_axis(self.yaxis)

lib/matplotlib/spines.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,18 @@ def register_axis(self, axis):
228228
"""
229229
self.axis = axis
230230
if self.axis is not None:
231-
self.axis.cla()
231+
self.axis.clear()
232232
self.stale = True
233233

234-
def cla(self):
234+
def clear(self):
235235
"""Clear the current spine."""
236236
self._position = None # clear position
237237
if self.axis is not None:
238-
self.axis.cla()
238+
self.axis.clear()
239+
240+
@cbook.deprecated("3.4", alternative="Spine.clear()")
241+
def cla(self):
242+
self.clear()
239243

240244
def _adjust_location(self):
241245
"""Automatically set spine bounds to the view interval."""

lib/mpl_toolkits/mplot3d/axes3d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ def cla(self):
10791079
# docstring inherited.
10801080

10811081
super().cla()
1082-
self.zaxis.cla()
1082+
self.zaxis.clear()
10831083

10841084
if self._sharez is not None:
10851085
self.zaxis.major = self._sharez.zaxis.major

0 commit comments

Comments
 (0)