Skip to content

Deprecate cla() methods of Axis and Spines in favor of clear() #18710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/axis_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Inheritance
:template: autosummary.rst
:nosignatures:

Axis.clear
Axis.cla
Axis.get_scale

Expand Down
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/deprecations/18710-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``Axis.cla()``, ``RadialAxis.cla()``, ``ThetaAxis.cla()`` and ``Spine.cla()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These methods are deprecated in favor of the respective ``clear()`` methods.
2 changes: 1 addition & 1 deletion examples/misc/custom_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _init_axis(self):
self.xaxis = maxis.XAxis(self)
self.yaxis = maxis.YAxis(self)
# Do not register xaxis or yaxis with spines -- as done in
# Axes._init_axis() -- until GeoAxes.xaxis.cla() works.
# Axes._init_axis() -- until GeoAxes.xaxis.clear() works.
# self.spines['geo'].register_axis(self.yaxis)
self._update_transScale()

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,11 +1100,11 @@ def cla(self):
xaxis_visible = self.xaxis.get_visible()
yaxis_visible = self.yaxis.get_visible()

self.xaxis.cla()
self.yaxis.cla()
self.xaxis.clear()
self.yaxis.clear()

for name, spine in self.spines.items():
spine.cla()
spine.clear()

self.ignore_existing_data_limits = True
self.callbacks = cbook.CallbackRegistry()
Expand Down
22 changes: 19 additions & 3 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def __init__(self, axes, pickradius=15):
self._major_tick_kw = dict()
self._minor_tick_kw = dict()

self.cla()
self.clear()
self._set_scale('linear')

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

def cla(self):
"""Clear this axis."""
def clear(self):
"""
Clear the axis.

This resets axis properties to their default values:

- the label
- the scale
- locators, formatters and ticks
- major and minor grid
- units
- registered callbacks
"""

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

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

@cbook.deprecated("3.4", alternative="Axis.clear()")
def cla(self):
"""Clear this axis."""
return self.clear()

def reset_ticks(self):
"""
Re-initialize the major and minor Tick lists.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/projections/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _init_axis(self):
self.xaxis = maxis.XAxis(self)
self.yaxis = maxis.YAxis(self)
# Do not register xaxis or yaxis with spines -- as done in
# Axes._init_axis() -- until GeoAxes.xaxis.cla() works.
# Axes._init_axis() -- until GeoAxes.xaxis.clear() works.
# self.spines['geo'].register_axis(self.yaxis)
self._update_transScale()

Expand Down
18 changes: 13 additions & 5 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,15 @@ def _wrap_locator_formatter(self):
self.isDefault_majloc = True
self.isDefault_majfmt = True

def cla(self):
super().cla()
def clear(self):
super().clear()
self.set_ticks_position('none')
self._wrap_locator_formatter()

@cbook.deprecated("3.4", alternative="ThetaAxis.clear()")
def cla(self):
self.clear()

def _set_scale(self, value, **kwargs):
super()._set_scale(value, **kwargs)
self._wrap_locator_formatter()
Expand Down Expand Up @@ -680,11 +684,15 @@ def _wrap_locator_formatter(self):
self.axes))
self.isDefault_majloc = True

def cla(self):
super().cla()
def clear(self):
super().clear()
self.set_ticks_position('none')
self._wrap_locator_formatter()

@cbook.deprecated("3.4", alternative="RadialAxis.clear()")
def cla(self):
self.clear()

def _set_scale(self, value, **kwargs):
super()._set_scale(value, **kwargs)
self._wrap_locator_formatter()
Expand Down Expand Up @@ -810,7 +818,7 @@ def _init_axis(self):
# This is moved out of __init__ because non-separable axes don't use it
self.xaxis = ThetaAxis(self)
self.yaxis = RadialAxis(self)
# Calling polar_axes.xaxis.cla() or polar_axes.xaxis.cla()
# Calling polar_axes.xaxis.clear() or polar_axes.xaxis.clear()
# results in weird artifacts. Therefore we disable this for
# now.
# self.spines['polar'].register_axis(self.yaxis)
Expand Down
10 changes: 7 additions & 3 deletions lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,18 @@ def register_axis(self, axis):
"""
self.axis = axis
if self.axis is not None:
self.axis.cla()
self.axis.clear()
self.stale = True

def cla(self):
def clear(self):
"""Clear the current spine."""
self._position = None # clear position
if self.axis is not None:
self.axis.cla()
self.axis.clear()

@cbook.deprecated("3.4", alternative="Spine.clear()")
def cla(self):
self.clear()

def _adjust_location(self):
"""Automatically set spine bounds to the view interval."""
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def cla(self):
# docstring inherited.

super().cla()
self.zaxis.cla()
self.zaxis.clear()

if self._sharez is not None:
self.zaxis.major = self._sharez.zaxis.major
Expand Down