Skip to content

Commit bccc557

Browse files
committed
[MNT]: make Axes.cla an alias for Axes.clear in all cases
1 parent 9caa261 commit bccc557

File tree

15 files changed

+114
-37
lines changed

15 files changed

+114
-37
lines changed

examples/misc/custom_projection.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def _init_axis(self):
5252
# self.spines['geo'].register_axis(self.yaxis)
5353
self._update_transScale()
5454

55-
def cla(self):
56-
super().cla()
55+
def clear(self):
56+
# docstring inherited
57+
super().clear()
5758

5859
self.set_longitude_grid(30)
5960
self.set_latitude_grid(15)
@@ -71,6 +72,10 @@ def cla(self):
7172
Axes.set_xlim(self, -np.pi, np.pi)
7273
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
7374

75+
def cla(self):
76+
"""Clear the current axes."""
77+
self.clear()
78+
7479
def _set_lim_and_transforms(self):
7580
# A (possibly non-linear) projection on the (already scaled) data
7681

@@ -424,7 +429,7 @@ def __init__(self, *args, **kwargs):
424429
self._longitude_cap = np.pi / 2.0
425430
super().__init__(*args, **kwargs)
426431
self.set_aspect(0.5, adjustable='box', anchor='C')
427-
self.cla()
432+
self.clear()
428433

429434
def _get_core_transform(self, resolution):
430435
return self.HammerTransform(resolution)

lib/matplotlib/axes/_base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def __init__(self, fig, rect,
641641
self.set_axisbelow(mpl.rcParams['axes.axisbelow'])
642642

643643
self._rasterization_zorder = None
644-
self.cla()
644+
self.clear()
645645

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

1196-
def cla(self):
1196+
def clear(self):
11971197
"""Clear the Axes."""
11981198
# Note: this is called by Axes.__init__()
11991199

@@ -1487,9 +1487,9 @@ def texts(self):
14871487
return self.ArtistList(self, 'texts', 'add_artist',
14881488
valid_types=mtext.Text)
14891489

1490-
def clear(self):
1490+
def cla(self):
14911491
"""Clear the Axes."""
1492-
self.cla()
1492+
self.clear()
14931493

14941494
def get_facecolor(self):
14951495
"""Get the facecolor of the Axes."""

lib/matplotlib/figure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def clear(self, keep_observers=False):
932932
self.subfigs = []
933933

934934
for ax in tuple(self.axes): # Iterate over the copy.
935-
ax.cla()
935+
ax.clear()
936936
self.delaxes(ax) # Remove ax from self._axstack.
937937

938938
self.artists = []

lib/matplotlib/projections/geo.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def _init_axis(self):
3636
# self.spines['geo'].register_axis(self.yaxis)
3737
self._update_transScale()
3838

39-
def cla(self):
40-
super().cla()
39+
def clear(self):
40+
# docstring inherited
41+
super().clear()
4142

4243
self.set_longitude_grid(30)
4344
self.set_latitude_grid(15)
@@ -55,6 +56,10 @@ def cla(self):
5556
Axes.set_xlim(self, -np.pi, np.pi)
5657
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
5758

59+
def cla(self):
60+
"""Clear the current axes."""
61+
self.clear()
62+
5863
def _set_lim_and_transforms(self):
5964
# A (possibly non-linear) projection on the (already scaled) data
6065
self.transProjection = self._get_core_transform(self.RESOLUTION)
@@ -284,7 +289,7 @@ def __init__(self, *args, **kwargs):
284289
self._longitude_cap = np.pi / 2.0
285290
super().__init__(*args, **kwargs)
286291
self.set_aspect(0.5, adjustable='box', anchor='C')
287-
self.cla()
292+
self.clear()
288293

289294
def _get_core_transform(self, resolution):
290295
return self.AitoffTransform(resolution)
@@ -329,7 +334,7 @@ def __init__(self, *args, **kwargs):
329334
self._longitude_cap = np.pi / 2.0
330335
super().__init__(*args, **kwargs)
331336
self.set_aspect(0.5, adjustable='box', anchor='C')
332-
self.cla()
337+
self.clear()
333338

334339
def _get_core_transform(self, resolution):
335340
return self.HammerTransform(resolution)
@@ -399,7 +404,7 @@ def __init__(self, *args, **kwargs):
399404
self._longitude_cap = np.pi / 2.0
400405
super().__init__(*args, **kwargs)
401406
self.set_aspect(0.5, adjustable='box', anchor='C')
402-
self.cla()
407+
self.clear()
403408

404409
def _get_core_transform(self, resolution):
405410
return self.MollweideTransform(resolution)
@@ -484,12 +489,17 @@ def __init__(self, *args, center_longitude=0, center_latitude=0, **kwargs):
484489
self._center_latitude = center_latitude
485490
super().__init__(*args, **kwargs)
486491
self.set_aspect('equal', adjustable='box', anchor='C')
487-
self.cla()
492+
self.clear()
488493

489-
def cla(self):
490-
super().cla()
494+
def clear(self):
495+
# docstring inherited
496+
super().clear()
491497
self.yaxis.set_major_formatter(NullFormatter())
492498

499+
def cla(self):
500+
"""Clear the current axes."""
501+
self.clear()
502+
493503
def _get_core_transform(self, resolution):
494504
return self.LambertTransform(
495505
self._center_longitude,

lib/matplotlib/projections/polar.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,14 @@ def _wrap_locator_formatter(self):
373373
self.isDefault_majfmt = True
374374

375375
def clear(self):
376+
# docstring inherited
376377
super().clear()
377378
self.set_ticks_position('none')
378379
self._wrap_locator_formatter()
379380

380381
@_api.deprecated("3.4", alternative="ThetaAxis.clear()")
381382
def cla(self):
383+
"""Clear the current axes."""
382384
self.clear()
383385

384386
def _set_scale(self, value, **kwargs):
@@ -671,12 +673,14 @@ def _wrap_locator_formatter(self):
671673
self.isDefault_majloc = True
672674

673675
def clear(self):
676+
# docstring inherited
674677
super().clear()
675678
self.set_ticks_position('none')
676679
self._wrap_locator_formatter()
677680

678681
@_api.deprecated("3.4", alternative="RadialAxis.clear()")
679682
def cla(self):
683+
"""Clear the current axes."""
680684
self.clear()
681685

682686
def _set_scale(self, value, **kwargs):
@@ -776,10 +780,11 @@ def __init__(self, *args,
776780
super().__init__(*args, **kwargs)
777781
self.use_sticky_edges = True
778782
self.set_aspect('equal', adjustable='box', anchor='C')
779-
self.cla()
783+
self.clear()
780784

781-
def cla(self):
782-
super().cla()
785+
def clear(self):
786+
# docstring inherited
787+
super().clear()
783788

784789
self.title.set_y(1.05)
785790

@@ -800,6 +805,10 @@ def cla(self):
800805
self.set_theta_offset(self._default_theta_offset)
801806
self.set_theta_direction(self._default_theta_direction)
802807

808+
def cla(self):
809+
"""Clear the current axes."""
810+
self.clear()
811+
803812
def _init_axis(self):
804813
# This is moved out of __init__ because non-separable axes don't use it
805814
self.xaxis = ThetaAxis(self)

lib/matplotlib/pyplot.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,12 @@ def sca(ax):
11081108
def cla():
11091109
"""Clear the current axes."""
11101110
# Not generated via boilerplate.py to allow a different docstring.
1111-
return gca().cla()
1111+
clear()
1112+
1113+
1114+
def clear():
1115+
"""Clear the current axes."""
1116+
return gca().clear()
11121117

11131118

11141119
## More ways of creating axes ##

lib/matplotlib/spines.py

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def clear(self):
224224

225225
@_api.deprecated("3.4", alternative="`.Spine.clear`")
226226
def cla(self):
227+
"""Clear the Axes."""
227228
self.clear()
228229

229230
def _adjust_location(self):

lib/matplotlib/tests/test_axes.py

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import matplotlib.colors as mcolors
2323
import matplotlib.dates as mdates
2424
from matplotlib.figure import Figure
25+
from matplotlib.axis import Axis
2526
import matplotlib.font_manager as mfont_manager
2627
import matplotlib.markers as mmarkers
2728
import matplotlib.patches as mpatches
@@ -468,6 +469,12 @@ def test_inverted_cla():
468469
plt.close(fig)
469470

470471

472+
def test_cla_not_redefined():
473+
for klass in Axis.__subclasses__():
474+
# check that subclasses do not get redefined in our Axis subclasses
475+
assert 'cla' not in klass.__dict__
476+
477+
471478
@check_figures_equal(extensions=["png"])
472479
def test_minorticks_on_rcParams_both(fig_test, fig_ref):
473480
with matplotlib.rc_context({"xtick.minor.visible": True,

lib/matplotlib/tests/test_figure.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,18 @@ def test_figure_clear(clear_meth):
791791
assert fig.axes == []
792792

793793

794-
def test_clf_not_refedined():
794+
def test_clf_not_redefined():
795795
for klass in FigureBase.__subclasses__():
796796
# check that subclasses do not get redefined in our Figure subclasses
797797
assert 'clf' not in klass.__dict__
798798

799799

800+
def test_cla_not_redefined():
801+
for klass in FigureBase.__subclasses__():
802+
# check that subclasses do not get redefined in our Figure subclasses
803+
assert 'cla' not in klass.__dict__
804+
805+
800806
@mpl.style.context('mpl20')
801807
def test_picking_does_not_stale():
802808
fig, ax = plt.subplots()

lib/mpl_toolkits/axes_grid1/axes_grid.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ def toggle_label(self, b):
3737
axis = self.axis[self.orientation]
3838
axis.toggle(ticklabels=b, label=b)
3939

40-
def cla(self):
40+
def clear(self):
41+
# docstring inherited
42+
4143
orientation = self.orientation
42-
super().cla()
44+
super().clear()
4345
self.orientation = orientation
4446

47+
def cla(self):
48+
"""Clear the current axes."""
49+
self.clear()
50+
4551

4652
@_api.deprecated("3.5")
4753
class CbarAxes(CbarAxesBase, Axes):

lib/mpl_toolkits/axes_grid1/mpl_axes.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ def _init_axis_artists(self):
5252
def axis(self):
5353
return self._axislines
5454

55-
def cla(self):
56-
super().cla()
55+
def clear(self):
56+
# docstring inherited
57+
super().clear()
5758
self._init_axis_artists()
5859

60+
def cla(self):
61+
"""Clear the current axes."""
62+
self.clear()
63+
5964

6065
class SimpleAxisArtist(Artist):
6166
def __init__(self, axis, axisnum, spine):

lib/mpl_toolkits/axes_grid1/parasite_axes.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ def __init__(self, parent_axes, aux_transform=None,
1717
kwargs["frameon"] = False
1818
super().__init__(parent_axes.figure, parent_axes._position, **kwargs)
1919

20-
def cla(self):
21-
super().cla()
20+
def clear(self):
21+
# docstring inherited
22+
super().clear()
2223
martist.setp(self.get_children(), visible=False)
2324
self._get_lines = self._parent_axes._get_lines
2425

26+
def cla(self):
27+
"""Clear the current axes."""
28+
self.clear()
29+
2530
@_api.deprecated("3.5")
2631
def get_images_artists(self):
2732
artists = []
@@ -138,10 +143,15 @@ def draw(self, renderer):
138143
super().draw(renderer)
139144
self._children = self._children[:orig_children_len]
140145

141-
def cla(self):
146+
def clear(self):
147+
# docstring inherited
142148
for ax in self.parasites:
143-
ax.cla()
144-
super().cla()
149+
ax.clear()
150+
super().clear()
151+
152+
def cla(self):
153+
"""Clear the current axes."""
154+
self.clear()
145155

146156
def pick(self, mouseevent):
147157
super().pick(mouseevent)

lib/mpl_toolkits/axisartist/axislines.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,22 @@ def _init_gridlines(self, grid_helper=None):
499499
# It is done inside the cla.
500500
self.gridlines = self.new_gridlines(grid_helper)
501501

502-
def cla(self):
502+
def clear(self):
503+
# docstring inherited
503504
# gridlines need to b created before cla() since cla calls grid()
504505
self._init_gridlines()
505-
super().cla()
506+
super().clear()
506507

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

511512
self._init_axis_artists()
512513

514+
def cla(self):
515+
"""Clear the current axes."""
516+
self.clear()
517+
513518
def get_grid_helper(self):
514519
return self._grid_helper
515520

lib/mpl_toolkits/axisartist/floating_axes.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ def _gen_axes_patch(self):
329329
patch.get_path()._interpolation_steps = 100
330330
return patch
331331

332-
def cla(self):
333-
super().cla()
332+
def clear(self):
333+
# docstring inherited
334+
super().clear()
334335
self.patch.set_transform(
335336
self.get_grid_helper().grid_finder.get_transform()
336337
+ self.transData)
@@ -342,6 +343,10 @@ def cla(self):
342343
self.patch.set_clip_path(orig_patch)
343344
self.gridlines.set_clip_path(orig_patch)
344345

346+
def cla(self):
347+
"""Clear the current axes."""
348+
self.clear()
349+
345350
def adjust_axes_lim(self):
346351
bbox = self.patch.get_path().get_extents(
347352
# First transform to pixel coords, then to parent data coords.

0 commit comments

Comments
 (0)