From 2357c92d87d96d519c8470776e76180e71663d0b Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 3 Mar 2022 02:07:12 +0100 Subject: [PATCH] Refactor handling of tick and ticklabel visiblity in Axis.clear() This is a follow-up to #20826, which makes the exceptions from clearing more explicit. --- lib/matplotlib/axis.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index dc3e75a2a629..4c09e2550768 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -781,14 +781,36 @@ def get_children(self): return [self.label, self.offsetText, *self.get_major_ticks(), *self.get_minor_ticks()] - def _reset_major_tick_kw(self): + def _reset_major_tick_kw(self, keep_tick_and_label_visibility=False): + """ + Reset major tick params to defaults. + + Shared subplots pre-configure tick and label visibility. To keep this + beyond an Axis.clear() operation, we may + *keep_tick_and_label_visibility*. + """ + backup = {name: value for name, value in self._major_tick_kw.items() + if name in ['tick1On', 'tick2On', 'label1On', 'label2On']} self._major_tick_kw.clear() + if keep_tick_and_label_visibility: + self._major_tick_kw.update(backup) self._major_tick_kw['gridOn'] = ( mpl.rcParams['axes.grid'] and mpl.rcParams['axes.grid.which'] in ('both', 'major')) - def _reset_minor_tick_kw(self): + def _reset_minor_tick_kw(self, keep_tick_and_label_visibility=False): + """ + Reset minor tick params to defaults. + + Shared subplots pre-configure tick and label visibility. To keep this + beyond an Axis.clear() operation, we may + *keep_tick_and_label_visibility*. + """ + backup = {name: value for name, value in self._minor_tick_kw.items() + if name in ['tick1On', 'tick2On', 'label1On', 'label2On']} self._minor_tick_kw.clear() + if keep_tick_and_label_visibility: + self._minor_tick_kw.update(backup) self._minor_tick_kw['gridOn'] = ( mpl.rcParams['axes.grid'] and mpl.rcParams['axes.grid.which'] in ('both', 'minor')) @@ -805,6 +827,8 @@ def clear(self): - major and minor grid - units - registered callbacks + + This does not reset tick and tick label visibility. """ self.label.set_text('') # self.set_label_text would change isDefault_ @@ -816,12 +840,8 @@ def clear(self): signals=["units", "units finalize"]) # whether the grids are on - self._major_tick_kw['gridOn'] = ( - mpl.rcParams['axes.grid'] and - mpl.rcParams['axes.grid.which'] in ('both', 'major')) - self._minor_tick_kw['gridOn'] = ( - mpl.rcParams['axes.grid'] and - mpl.rcParams['axes.grid.which'] in ('both', 'minor')) + self._reset_major_tick_kw(keep_tick_and_label_visibility=True) + self._reset_minor_tick_kw(keep_tick_and_label_visibility=True) self.reset_ticks() self.converter = None 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