diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 1ee97dc9078b..48006865631c 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -846,6 +846,13 @@ def get_children(self): return [self.label, self.offsetText, *self.get_major_ticks(), *self.get_minor_ticks()] + # style parameters that should be preserved by reset operations + _style_tick_params = [ + 'tick1On', 'tick2On', 'tickdir', + 'label1On', 'label2On', 'labelsize', 'labelcolor', 'labelrotation', + 'size', 'width', 'color', 'pad' + ] + def _reset_major_tick_kw(self, keep_tick_and_label_visibility=False): """ Reset major tick params to defaults. @@ -855,7 +862,7 @@ def _reset_major_tick_kw(self, keep_tick_and_label_visibility=False): *keep_tick_and_label_visibility*. """ backup = {name: value for name, value in self._major_tick_kw.items() - if name in ['tick1On', 'tick2On', 'label1On', 'label2On']} + if name in self.__class__._style_tick_params} self._major_tick_kw.clear() if keep_tick_and_label_visibility: self._major_tick_kw.update(backup) @@ -872,7 +879,7 @@ def _reset_minor_tick_kw(self, keep_tick_and_label_visibility=False): *keep_tick_and_label_visibility*. """ backup = {name: value for name, value in self._minor_tick_kw.items() - if name in ['tick1On', 'tick2On', 'label1On', 'label2On']} + if name in self.__class__._style_tick_params} self._minor_tick_kw.clear() if keep_tick_and_label_visibility: self._minor_tick_kw.update(backup) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a230af2ac1e0..05b55d504d74 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -7665,6 +7665,34 @@ def test_2dcolor_plot(fig_test, fig_ref): axs[4].bar(np.arange(10), np.arange(10), color=color.reshape((1, -1))) +@pytest.mark.parametrize( + # separate tested parameters into two collision-free sets + # (e.g. avoid supplying *color* and *colors* at the same time) + 'params', + [ + dict( + direction='in', length=2, width=5, color="red", pad=0.4, + bottom=False, top=True, left=False, right=True, + labelrotation=90, labelsize=20, + ), + dict( + colors="red", + bottom=True, top=True, left=True, right=True, + labelbottom=False, labeltop=True, labelleft=False, labelright=True, + ) + ] +) +@check_figures_equal(extensions=['png']) +def test_persistent_style_axes_clear(fig_test, fig_ref, params): + # see https://github.com/matplotlib/matplotlib/issues/23806 + ax = fig_ref.subplots(1, 1) + ax.tick_params(which='both', axis='both', **params) + + ax = fig_test.subplots(1, 1) + ax.tick_params(which='both', axis='both', **params) + ax.clear() + + @check_figures_equal(extensions=['png']) def test_shared_axes_clear(fig_test, fig_ref): x = np.arange(0.0, 2*np.pi, 0.01) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy