1515from matplotlib ._api .deprecation import MatplotlibDeprecationWarning
1616from matplotlib .testing .decorators import image_comparison , check_figures_equal
1717from matplotlib .axes import Axes
18- from matplotlib .figure import Figure
18+ from matplotlib .figure import Figure , FigureBase
1919from matplotlib .ticker import AutoMinorLocator , FixedFormatter , ScalarFormatter
2020import matplotlib .pyplot as plt
2121import matplotlib .dates as mdates
@@ -689,7 +689,8 @@ def test_removed_axis():
689689 fig .canvas .draw ()
690690
691691
692- def test_figure_clear ():
692+ @pytest .mark .parametrize ('clear_meth' , ['clear' , 'clf' ])
693+ def test_figure_clear (clear_meth ):
693694 # we test the following figure clearing scenarios:
694695 fig = plt .figure ()
695696
@@ -699,19 +700,19 @@ def test_figure_clear():
699700
700701 # b) a figure with a single unnested axes
701702 ax = fig .add_subplot (111 )
702- fig . clear ()
703+ getattr ( fig , clear_meth ) ()
703704 assert fig .axes == []
704705
705706 # c) a figure multiple unnested axes
706707 axes = [fig .add_subplot (2 , 1 , i + 1 ) for i in range (2 )]
707- fig . clear ()
708+ getattr ( fig , clear_meth ) ()
708709 assert fig .axes == []
709710
710711 # d) a figure with a subfigure
711712 gs = fig .add_gridspec (ncols = 2 , nrows = 1 )
712713 subfig = fig .add_subfigure (gs [0 ])
713714 subaxes = subfig .add_subplot (111 )
714- fig . clear ()
715+ getattr ( fig , clear_meth ) ()
715716 assert subfig not in fig .subfigs
716717 assert fig .axes == []
717718
@@ -735,15 +736,15 @@ def test_figure_clear():
735736 subaxes = subfig .add_subplot (111 )
736737 assert mainaxes in fig .axes
737738 assert subaxes in fig .axes
738- subfig . clear ()
739+ getattr ( subfig , clear_meth ) ()
739740 assert subfig in fig .subfigs
740741 assert subaxes not in subfig .axes
741742 assert subaxes not in fig .axes
742743 assert mainaxes in fig .axes
743744
744745 # e.4) clearing the whole thing
745746 subaxes = subfig .add_subplot (111 )
746- fig . clear ()
747+ getattr ( fig , clear_meth ) ()
747748 assert fig .axes == []
748749 assert fig .subfigs == []
749750
@@ -754,22 +755,28 @@ def test_figure_clear():
754755 assert all (sfig in fig .subfigs for sfig in subfigs )
755756
756757 # f.1) clearing only one subfigure
757- subfigs [0 ]. clear ()
758+ getattr ( subfigs [0 ], clear_meth ) ()
758759 assert subaxes [0 ] not in fig .axes
759760 assert subaxes [1 ] in fig .axes
760761 assert subfigs [1 ] in fig .subfigs
761762
762763 # f.2) clearing the whole thing
763- subfigs [1 ]. clear ()
764+ getattr ( subfigs [1 ], clear_meth ) ()
764765 subfigs = [fig .add_subfigure (gs [i ]) for i in [0 , 1 ]]
765766 subaxes = [sfig .add_subplot (111 ) for sfig in subfigs ]
766767 assert all (ax in fig .axes for ax in subaxes )
767768 assert all (sfig in fig .subfigs for sfig in subfigs )
768- fig . clear ()
769+ getattr ( fig , clear_meth ) ()
769770 assert fig .subfigs == []
770771 assert fig .axes == []
771772
772773
774+ def test_clf_not_refedined ():
775+ for klass in FigureBase .__subclasses__ ():
776+ # check that subclasses do not get redefined in our Figure subclasses
777+ assert 'clf' not in klass .__dict__
778+
779+
773780@mpl .style .context ('mpl20' )
774781def test_picking_does_not_stale ():
775782 fig , ax = plt .subplots ()
0 commit comments