Skip to content

MNT: make Axes.cla an alias for Axes.clear in all cases #22802

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
Apr 17, 2022
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
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/removals/22738-JL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Removal of deprecated methods in `matplotlib.projections.polar`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``cla`` method in both ``ThetaAxis`` and ``RadialAxis`` has been removed
after being deprecated in 3.4. Use ``clear`` instead.

Removal of deprecated methods in `matplotlib.spines`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``cla`` method in ``Spine`` is removed after being deprecated in 3.4.
Use ``clear`` instead.
7 changes: 4 additions & 3 deletions examples/misc/custom_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def _init_axis(self):
# self.spines['geo'].register_axis(self.yaxis)
self._update_transScale()

def cla(self):
super().cla()
def clear(self):
# docstring inherited
super().clear()

self.set_longitude_grid(30)
self.set_latitude_grid(15)
Expand Down Expand Up @@ -424,7 +425,7 @@ def __init__(self, *args, **kwargs):
self._longitude_cap = np.pi / 2.0
super().__init__(*args, **kwargs)
self.set_aspect(0.5, adjustable='box', anchor='C')
self.cla()
self.clear()

def _get_core_transform(self, resolution):
return self.HammerTransform(resolution)
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def __init__(self, fig, rect,
self.set_axisbelow(mpl.rcParams['axes.axisbelow'])

self._rasterization_zorder = None
self.cla()
self.clear()

# funcs used to format x and y - fall back on major formatters
self.fmt_xdata = None
Expand Down Expand Up @@ -1193,7 +1193,7 @@ def sharey(self, other):
self.set_ylim(y0, y1, emit=False, auto=other.get_autoscaley_on())
self.yaxis._scale = other.yaxis._scale

def cla(self):
def clear(self):
"""Clear the Axes."""
# Note: this is called by Axes.__init__()

Expand Down Expand Up @@ -1487,9 +1487,9 @@ def texts(self):
return self.ArtistList(self, 'texts', 'add_artist',
valid_types=mtext.Text)

def clear(self):
def cla(self):
"""Clear the Axes."""
self.cla()
self.clear()

def get_facecolor(self):
"""Get the facecolor of the Axes."""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def clear(self, keep_observers=False):
self.subfigs = []

for ax in tuple(self.axes): # Iterate over the copy.
ax.cla()
ax.clear()
self.delaxes(ax) # Remove ax from self._axstack.

self.artists = []
Expand Down
18 changes: 10 additions & 8 deletions lib/matplotlib/projections/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def _init_axis(self):
# self.spines['geo'].register_axis(self.yaxis)
self._update_transScale()

def cla(self):
super().cla()
def clear(self):
# docstring inherited
super().clear()

self.set_longitude_grid(30)
self.set_latitude_grid(15)
Expand Down Expand Up @@ -284,7 +285,7 @@ def __init__(self, *args, **kwargs):
self._longitude_cap = np.pi / 2.0
super().__init__(*args, **kwargs)
self.set_aspect(0.5, adjustable='box', anchor='C')
self.cla()
self.clear()

def _get_core_transform(self, resolution):
return self.AitoffTransform(resolution)
Expand Down Expand Up @@ -329,7 +330,7 @@ def __init__(self, *args, **kwargs):
self._longitude_cap = np.pi / 2.0
super().__init__(*args, **kwargs)
self.set_aspect(0.5, adjustable='box', anchor='C')
self.cla()
self.clear()

def _get_core_transform(self, resolution):
return self.HammerTransform(resolution)
Expand Down Expand Up @@ -399,7 +400,7 @@ def __init__(self, *args, **kwargs):
self._longitude_cap = np.pi / 2.0
super().__init__(*args, **kwargs)
self.set_aspect(0.5, adjustable='box', anchor='C')
self.cla()
self.clear()

def _get_core_transform(self, resolution):
return self.MollweideTransform(resolution)
Expand Down Expand Up @@ -484,10 +485,11 @@ def __init__(self, *args, center_longitude=0, center_latitude=0, **kwargs):
self._center_latitude = center_latitude
super().__init__(*args, **kwargs)
self.set_aspect('equal', adjustable='box', anchor='C')
self.cla()
self.clear()

def cla(self):
super().cla()
def clear(self):
# docstring inherited
super().clear()
self.yaxis.set_major_formatter(NullFormatter())

def _get_core_transform(self, resolution):
Expand Down
17 changes: 6 additions & 11 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,11 @@ def _wrap_locator_formatter(self):
self.isDefault_majfmt = True

def clear(self):
# docstring inherited
super().clear()
self.set_ticks_position('none')
self._wrap_locator_formatter()

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

def _set_scale(self, value, **kwargs):
if value != 'linear':
raise NotImplementedError(
Expand Down Expand Up @@ -671,14 +668,11 @@ def _wrap_locator_formatter(self):
self.isDefault_majloc = True

def clear(self):
# docstring inherited
super().clear()
self.set_ticks_position('none')
self._wrap_locator_formatter()

@_api.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 @@ -776,10 +770,11 @@ def __init__(self, *args,
super().__init__(*args, **kwargs)
self.use_sticky_edges = True
self.set_aspect('equal', adjustable='box', anchor='C')
self.cla()
self.clear()

def cla(self):
super().cla()
def clear(self):
# docstring inherited
super().clear()

self.title.set_y(1.05)

Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ def clear(self):
if self.axis is not None:
self.axis.clear()

@_api.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
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import matplotlib.colors as mcolors
import matplotlib.dates as mdates
from matplotlib.figure import Figure
from matplotlib.axes import Axes
import matplotlib.font_manager as mfont_manager
import matplotlib.markers as mmarkers
import matplotlib.patches as mpatches
Expand Down Expand Up @@ -468,6 +469,12 @@ def test_inverted_cla():
plt.close(fig)


def test_cla_not_redefined():
for klass in Axes.__subclasses__():
# check that cla does not get redefined in our Axes subclasses
assert 'cla' not in klass.__dict__


@check_figures_equal(extensions=["png"])
def test_minorticks_on_rcParams_both(fig_test, fig_ref):
with matplotlib.rc_context({"xtick.minor.visible": True,
Expand Down
5 changes: 3 additions & 2 deletions lib/mpl_toolkits/axes_grid1/mpl_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def _init_axis_artists(self):
def axis(self):
return self._axislines

def cla(self):
super().cla()
def clear(self):
# docstring inherited
super().clear()
self._init_axis_artists()


Expand Down
10 changes: 5 additions & 5 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __init__(self, parent_axes, aux_transform=None,
kwargs["frameon"] = False
super().__init__(parent_axes.figure, parent_axes._position, **kwargs)

def cla(self):
super().cla()
def clear(self):
super().clear()
martist.setp(self.get_children(), visible=False)
self._get_lines = self._parent_axes._get_lines

Expand Down Expand Up @@ -138,10 +138,10 @@ def draw(self, renderer):
super().draw(renderer)
self._children = self._children[:orig_children_len]

def cla(self):
def clear(self):
for ax in self.parasites:
ax.cla()
super().cla()
ax.clear()
super().clear()

def pick(self, mouseevent):
super().pick(mouseevent)
Expand Down
9 changes: 5 additions & 4 deletions lib/mpl_toolkits/axisartist/axislines.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,13 @@ def _init_gridlines(self, grid_helper=None):
# It is done inside the cla.
self.gridlines = self.new_gridlines(grid_helper)

def cla(self):
# gridlines need to b created before cla() since cla calls grid()
def clear(self):
# docstring inherited
# gridlines need to be created before clear() since clear calls grid()
self._init_gridlines()
super().cla()
super().clear()

# the clip_path should be set after Axes.cla() since that's
# the clip_path should be set after Axes.clear() since that's
# when a patch is created.
self.gridlines.set_clip_path(self.axes.patch)

Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/axisartist/floating_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def _gen_axes_patch(self):
patch.get_path()._interpolation_steps = 100
return patch

def cla(self):
super().cla()
def clear(self):
super().clear()
self.patch.set_transform(
self.get_grid_helper().grid_finder.get_transform()
+ self.transData)
Expand Down
5 changes: 2 additions & 3 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,9 @@ def can_pan(self):
"""
return False

def cla(self):
def clear(self):
# docstring inherited.

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

if self._sharez is not None:
Expand Down