MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_figure_clear

Function test_figure_clear

lib/matplotlib/tests/test_figure.py:883–961  ·  view source on GitHub ↗
(clear_meth)

Source from the content-addressed store, hash-verified

881
882@pytest.mark.parametrize('clear_meth', ['clear', 'clf'])
883def test_figure_clear(clear_meth):
884 # we test the following figure clearing scenarios:
885 fig = plt.figure()
886
887 # a) an empty figure
888 fig.clear()
889 assert fig.axes == []
890
891 # b) a figure with a single unnested axes
892 ax = fig.add_subplot(111)
893 getattr(fig, clear_meth)()
894 assert fig.axes == []
895
896 # c) a figure multiple unnested axes
897 axes = [fig.add_subplot(2, 1, i+1) for i in range(2)]
898 getattr(fig, clear_meth)()
899 assert fig.axes == []
900
901 # d) a figure with a subfigure
902 gs = fig.add_gridspec(ncols=2, nrows=1)
903 subfig = fig.add_subfigure(gs[0])
904 subaxes = subfig.add_subplot(111)
905 getattr(fig, clear_meth)()
906 assert subfig not in fig.subfigs
907 assert fig.axes == []
908
909 # e) a figure with a subfigure and a subplot
910 subfig = fig.add_subfigure(gs[0])
911 subaxes = subfig.add_subplot(111)
912 mainaxes = fig.add_subplot(gs[1])
913
914 # e.1) removing just the axes leaves the subplot
915 mainaxes.remove()
916 assert fig.axes == [subaxes]
917
918 # e.2) removing just the subaxes leaves the subplot
919 # and subfigure
920 mainaxes = fig.add_subplot(gs[1])
921 subaxes.remove()
922 assert fig.axes == [mainaxes]
923 assert subfig in fig.subfigs
924
925 # e.3) clearing the subfigure leaves the subplot
926 subaxes = subfig.add_subplot(111)
927 assert mainaxes in fig.axes
928 assert subaxes in fig.axes
929 getattr(subfig, clear_meth)()
930 assert subfig in fig.subfigs
931 assert subaxes not in subfig.axes
932 assert subaxes not in fig.axes
933 assert mainaxes in fig.axes
934
935 # e.4) clearing the whole thing
936 subaxes = subfig.add_subplot(111)
937 getattr(fig, clear_meth)()
938 assert fig.axes == []
939 assert fig.subfigs == []
940

Callers

nothing calls this directly

Calls 6

figureMethod · 0.80
add_subplotMethod · 0.80
add_gridspecMethod · 0.80
add_subfigureMethod · 0.80
clearMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…