Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe563e3

Browse files
committed
review comments
1 parent ceef40c commit fe563e3

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -559,18 +559,19 @@ def __get__(self, instance, owner):
559559
# created and assigned afterwards.
560560
attr = 'majorTicks' if self._major else 'minorTicks'
561561
setattr(instance, attr, [])
562-
# Build the Tick (and its sub-artists) under the rcParams snapshot
563-
# taken at the last ``Axis.clear`` so that a lazily-materialized
564-
# Tick matches the values an eager (pre-lazy) Tick would have had
565-
# (see ``Axis._rc_snapshot``). Use ``_update_raw`` rather than
566-
# ``rc_context`` to bypass validators that would otherwise fire
567-
# spurious warnings when re-applying settings like
568-
# ``rcParams['toolbar'] = 'toolmanager'``.
569-
snapshot = instance._rc_snapshot
570-
if snapshot is not None:
562+
# Build the Tick (and its sub-artists) under the rcParams captured
563+
# at the last ``Axis.clear`` so that a lazily-materialized Tick
564+
# matches an eager (pre-lazy) Tick (see ``Axis._tick_rcParams``).
565+
# We avoid ``rc_context`` here because it re-applies rcParams via
566+
# ``RcParams.__setitem__``, whose validators emit warnings on every
567+
# assignment for keys like ``toolbar='toolmanager'`` -- re-setting
568+
# the snapshot to its own (identical) values would spuriously
569+
# re-trigger those warnings. ``_update_raw`` bypasses the validators
570+
# on both entry and exit.
571+
if instance._tick_rcParams is not None:
571572
rc = mpl.rcParams
572573
orig = dict(rc)
573-
rc._update_raw(snapshot)
574+
rc._update_raw(instance._tick_rcParams)
574575
try:
575576
tick = instance._get_tick(major=self._major)
576577
finally:
@@ -696,12 +697,14 @@ def __init__(self, axes, *, pickradius=15, clear=True):
696697
self._major_tick_kw = dict()
697698
self._minor_tick_kw = dict()
698699
# Snapshot of rcParams at the time of the last ``Axis.clear`` (or
699-
# ``set_tick_params(reset=True)``). ``_LazyTickList`` applies this
700-
# via ``rc_context`` when it lazily creates a Tick so that the Tick
701-
# and its sub-artists see the same rcParams an eager (pre-lazy)
702-
# materialization would have seen. See ``_propagate_axis_state_to_tick``
703-
# for the clip-state counterpart.
704-
self._rc_snapshot = None
700+
# ``set_tick_params(reset=True)``). ``_LazyTickList`` re-applies
701+
# these when it lazily creates a Tick so that the Tick and its
702+
# sub-artists see the same rcParams an eager (pre-lazy)
703+
# materialization would have seen. Kept separate from
704+
# ``_major_tick_kw``/``_minor_tick_kw``, which hold user-provided
705+
# ``set_tick_params`` overrides rather than ambient rcParams. See
706+
# ``_propagate_axis_state_to_tick`` for the clip-state counterpart.
707+
self._tick_rcParams = None
705708

706709
if clear:
707710
self.clear()
@@ -898,14 +901,14 @@ def _reset_major_tick_kw(self):
898901
self._major_tick_kw['gridOn'] = (
899902
mpl.rcParams['axes.grid'] and
900903
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
901-
self._rc_snapshot = dict(mpl.rcParams)
904+
self._tick_rcParams = dict(mpl.rcParams)
902905

903906
def _reset_minor_tick_kw(self):
904907
self._minor_tick_kw.clear()
905908
self._minor_tick_kw['gridOn'] = (
906909
mpl.rcParams['axes.grid'] and
907910
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
908-
self._rc_snapshot = dict(mpl.rcParams)
911+
self._tick_rcParams = dict(mpl.rcParams)
909912

910913
def clear(self):
911914
"""
@@ -939,7 +942,7 @@ def clear(self):
939942
# Snapshot current rcParams so that a Tick materialized later by
940943
# ``_LazyTickList`` (possibly outside any ``rc_context`` active
941944
# now) sees the same rcParams an eager pre-lazy tick would have.
942-
self._rc_snapshot = dict(mpl.rcParams)
945+
self._tick_rcParams = dict(mpl.rcParams)
943946

944947
# whether the grids are on
945948
self._major_tick_kw['gridOn'] = (
@@ -961,7 +964,9 @@ def reset_ticks(self):
961964
962965
Each list starts with a single fresh Tick.
963966
"""
964-
# Restore the lazy tick lists.
967+
# Drop any materialized tick lists so the _LazyTickList descriptor is
968+
# reactivated on next access. If ticks were already materialized,
969+
# re-apply the axes-patch clip path; otherwise skip.
965970
had_major = bool(self.__dict__.pop('majorTicks', None))
966971
had_minor = bool(self.__dict__.pop('minorTicks', None))
967972
if had_major or had_minor:

0 commit comments

Comments
 (0)