8000 MNT: prefer "clear" as canonical over clf · matplotlib/matplotlib@f37add1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f37add1

Browse files
committed
MNT: prefer "clear" as canonical over clf
1 parent a395083 commit f37add1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lib/matplotlib/figure.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def _break_share_link(ax, grouper):
913913
# Break link between any twinned axes
914914
_break_share_link(ax, ax._twinned_axes)
915915

916-
def clf(self, keep_observers=False):
916+
def clear(self, keep_observers=False):
917917
"""
918918
Clear the figure.
919919
@@ -928,7 +928,7 @@ def clf(self, keep_observers=False):
928928

929929
# first clear the axes in any subfigures
930930
for subfig in self.subfigs:
931-
subfig.clf(keep_observers=keep_observers)
931+
subfig.clear(keep_observers=keep_observers)
932932
self.subfigs = []
933933

934934
for ax in tuple(self.axes): # Iterate over the copy.
@@ -949,8 +949,8 @@ def clf(self, keep_observers=False):
949949

950950
self.stale = True
951951

952-
# synonym for `clf`."""
953-
clear = clf
952+
# synonym for `clear`.
953+
clf = clear
954954

955955
# Note: in the docstring below, the newlines in the examples after the
956956
# calls to legend() allow replacing it with figlegend() to generate the
@@ -2340,7 +2340,7 @@ def __init__(self,
23402340
self.subplotpars = subplotpars
23412341

23422342
self._axstack = _AxesStack() # track all figure axes and current axes
2343-
self.clf()
2343+
self.clear()
23442344
self._cachedRenderer = None
23452345

23462346
# list of child gridspecs for this figure
@@ -2839,15 +2839,18 @@ def set_figheight(self, val, forward=True):
28392839
"""
28402840
self.set_size_inches(self.get_figwidth(), val, forward=forward)
28412841

2842-
def clf(self, keep_observers=False):
2842+
def clear(self, keep_observers=False):
28432843
# docstring inherited
2844-
super().clf(keep_observers=keep_observers)
2845-
# FigureBase.clf does not clear toolbars, as
2844+
super().clear(keep_observers=keep_observers)
2845+
# FigureBase.clear does not clear toolbars, as
28462846
# only Figure can have toolbars
28472847
toolbar = self.canvas.toolbar
28482848
if toolbar is not None:
28492849
toolbar.update()
28502850

2851+
# synonym for `clear`.
2852+
clf = clear
2853+
28512854
@_finalize_rasterization
28522855
@allow_rasterization
28532856
def draw(self, renderer):

lib/matplotlib/tests/test_figure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
1717
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1818
from matplotlib.axes import Axes
19-
from matplotlib.figure import Figure
19+
from matplotlib.figure import Figure, FigureBase
2020
from matplotlib.layout_engine import (ConstrainedLayoutEngine,
2121
TightLayoutEngine)
2222
from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter
@@ -790,6 +790,12 @@ def test_figure_clear():
790790
assert fig.axes == []
791791

792792

793+
def test_clf_is_clear():
794+
for cls in [FigureBase] + FigureBase.__subclasses__():
795+
assert cls.clf is cls.clear
796+
assert cls.clear.__name__ == 'clear'
797+
798+
793799
@mpl.style.context('mpl20')
794800
def test_picking_does_not_stale():
795801
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)
0