From dd19976c2d96e693a5b1b139900f5ab2114571ca Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 6 Dec 2023 16:08:14 -0500 Subject: [PATCH 1/3] TST: adding tests of current clear behavior on ticks closes #23839 --- lib/matplotlib/tests/test_axes.py | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d5424f80c9e9..37be1911d8e8 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8898,3 +8898,43 @@ def test_axhvlinespan_interpolation(): ax.axhline(1, c="C0", alpha=.5) ax.axhspan(.8, .9, fc="C1", alpha=.5) ax.axhspan(.6, .7, .8, .9, fc="C2", alpha=.5) + + +@check_figures_equal(extensions=["png"]) +@pytest.mark.parametrize("which", ("x", "y")) +def test_axes_clear_behavior(fig_ref, fig_test, which): + ax_test = fig_test.subplots() + ax_ref = fig_ref.subplots() + target = { + "direction": "in", + "length": 10, + "width": 10, + "color": "xkcd:wine red", + "pad": 0, + "labelfontfamily": "serif", + "zorder": 7, + "labelrotation": 45, + "labelcolor": "xkcd:shocking pink", + # this overrides color + labelcolor, skip + # colors: , + "grid_color": "xkcd:fluorescent green", + "grid_alpha": 0.5, + "grid_linewidth": 3, + "grid_linestyle": ":", + "bottom": False, + "top": True, + "left": False, + "right": True, + "labelbottom": True, + "labeltop": True, + "labelleft": True, + "labelright": True, + } + + ax_ref.tick_params(axis=which, **target) + + ax_test.tick_params(axis=which, **target) + ax_test.clear() + + ax_ref.grid(True) + ax_test.grid(True) From ff470cfb57eeecad6e08e1bcb61512e22bba3c33 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 6 Mar 2024 16:09:13 -0500 Subject: [PATCH 2/3] DOC: update comments and docstrings Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/tests/test_axes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 37be1911d8e8..73a3ead26ea0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8903,8 +8903,11 @@ def test_axhvlinespan_interpolation(): @check_figures_equal(extensions=["png"]) @pytest.mark.parametrize("which", ("x", "y")) def test_axes_clear_behavior(fig_ref, fig_test, which): + """Test that the given tick params are not reset by ax.clear().""" ax_test = fig_test.subplots() ax_ref = fig_ref.subplots() + # the following tick params values are chosen to each create a visual difference + # from their defaults target = { "direction": "in", "length": 10, From 5bc7c6727ea92ef5e962b4df2f262aa75a7293e7 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 6 Mar 2024 15:33:17 -0600 Subject: [PATCH 3/3] Update lib/matplotlib/tests/test_axes.py --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 73a3ead26ea0..2751273db3d9 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8907,7 +8907,7 @@ def test_axes_clear_behavior(fig_ref, fig_test, which): ax_test = fig_test.subplots() ax_ref = fig_ref.subplots() # the following tick params values are chosen to each create a visual difference - # from their defaults + # from their defaults target = { "direction": "in", "length": 10,