From ec95f99e484937a560ae60df46928ba63b60db07 Mon Sep 17 00:00:00 2001 From: Jake Li Date: Thu, 7 Apr 2022 23:22:17 -0400 Subject: [PATCH] Co-authored-by: Neil Gurnani --- doc/api/next_api_changes/removals/22738-JL.rst | 10 ++++++++++ examples/misc/custom_projection.py | 7 ++++--- lib/matplotlib/axes/_base.py | 8 ++++---- lib/matplotlib/figure.py | 2 +- lib/matplotlib/projections/geo.py | 18 ++++++++++-------- lib/matplotlib/projections/polar.py | 17 ++++++----------- lib/matplotlib/spines.py | 4 ---- lib/matplotlib/tests/test_axes.py | 7 +++++++ lib/mpl_toolkits/axes_grid1/mpl_axes.py | 5 +++-- lib/mpl_toolkits/axes_grid1/parasite_axes.py | 10 +++++----- lib/mpl_toolkits/axisartist/axislines.py | 9 +++++---- lib/mpl_toolkits/axisartist/floating_axes.py | 4 ++-- lib/mpl_toolkits/mplot3d/axes3d.py | 5 ++--- 13 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 doc/api/next_api_changes/removals/22738-JL.rst diff --git a/doc/api/next_api_changes/removals/22738-JL.rst b/doc/api/next_api_changes/removals/22738-JL.rst new file mode 100644 index 000000000000..c1f50cd9d700 --- /dev/null +++ b/doc/api/next_api_changes/removals/22738-JL.rst @@ -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. diff --git a/examples/misc/custom_projection.py b/examples/misc/custom_projection.py index 034833f6a920..4f6e85fc30fd 100644 --- a/examples/misc/custom_projection.py +++ b/examples/misc/custom_projection.py @@ -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) @@ -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) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 38f77e537a02..b20f02c0891d 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -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 @@ -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__() @@ -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.""" diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index a8f953760a6f..f4a38bd6d5a5 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -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 = [] diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index ac3972cf146d..c9e378a98aa5 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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): diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 47a10d042903..370ef72f4ba4 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -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( @@ -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() @@ -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) diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index af8c60dece39..14216e10c255 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -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.""" diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 189187065191..7062de8d7655 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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 @@ -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, diff --git a/lib/mpl_toolkits/axes_grid1/mpl_axes.py b/lib/mpl_toolkits/axes_grid1/mpl_axes.py index 0057169e7f2b..7eb289ec0e42 100644 --- a/lib/mpl_toolkits/axes_grid1/mpl_axes.py +++ b/lib/mpl_toolkits/axes_grid1/mpl_axes.py @@ -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() diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index f3d1b1be59f9..389fd982de91 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -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 @@ -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) diff --git a/lib/mpl_toolkits/axisartist/axislines.py b/lib/mpl_toolkits/axisartist/axislines.py index 97e10dcd1b1a..d8f6d9358891 100644 --- a/lib/mpl_toolkits/axisartist/axislines.py +++ b/lib/mpl_toolkits/axisartist/axislines.py @@ -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) diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index a23ecb765ecd..21fe6d08fb87 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -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) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 0b6cc83216d0..aa2752ed11de 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -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: