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

Skip to content

Commit 1b72b8b

Browse files
eendebakptclaude
andcommitted
review comments: docstrings, comment style, spine helper
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent fe563e3 commit 1b72b8b

2 files changed

Lines changed: 36 additions & 37 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,18 +1436,17 @@ def __clear(self):
14361436
self.yaxis.set_clip_path(self.patch)
14371437

14381438
# Ensure spines have the correct transform before any subsequent
1439-
# layout or draw. Spine.__init__ installs ``self.axes.transData`` as
1439+
# layout or draw. Spine.__init__ installs self.axes.transData as
14401440
# a placeholder; the real blended transform is set by
1441-
# Spine.set_position (via ``_ensure_position_is_set``). Historically
1442-
# this fired as a side effect of tick materialization during clear;
1443-
# with lazy tick lists that cascade no longer runs, so nudge it here
1444-
# for spines that still carry the placeholder (projections like
1445-
# polar or secondary axes install custom transforms and are
1446-
# skipped).
1441+
# Spine.set_position via _ensure_position_is_set(). Historically
1442+
# this fired as a side effect of tick materialization during
1443+
# clear; with lazy tick lists that cascade no longer runs, so
1444+
# nudge it here for spines that still carry the placeholder
1445+
# (projections like polar or secondary axes install custom
1446+
# transforms and are skipped).
14471447
for spine in self.spines.values():
14481448
if spine._position is None and spine._transform is self.transData:
1449-
spine._position = ('outward', 0.0)
1450-
spine.set_transform(spine.get_spine_transform())
1449+
spine._ensure_position_is_set()
14511450

14521451
if self._sharex is not None:
14531452
self.xaxis.set_visible(xaxis_visible)

lib/matplotlib/axis.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def __init__(self, major):
548548
self._major = major
549549

550550
def __get__(self, instance, owner):
551+
"""Materialize the descriptor to a list with one configured tick."""
551552
if instance is None:
552553
return self
553554
# instance._get_tick() can itself try to access the majorTicks
@@ -560,13 +561,13 @@ def __get__(self, instance, owner):
560561
attr = 'majorTicks' if self._major else 'minorTicks'
561562
setattr(instance, attr, [])
562563
# 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
564+
# at the last Axis.clear() so that a lazily-materialized Tick
565+
# matches an eager (pre-lazy) Tick (see Axis._tick_rcParams).
566+
# We avoid rc_context() here because it re-applies rcParams via
567+
# RcParams.__setitem__, whose validators emit warnings on every
568+
# assignment for keys like toolbar='toolmanager' -- re-setting
568569
# the snapshot to its own (identical) values would spuriously
569-
# re-trigger those warnings. ``_update_raw`` bypasses the validators
570+
# re-trigger those warnings. _update_raw() bypasses the validators
570571
# on both entry and exit.
571572
if instance._tick_rcParams is not None:
572573
rc = mpl.rcParams
@@ -578,13 +579,13 @@ def __get__(self, instance, owner):
578579
rc._update_raw(orig)
579580
else:
580581
tick = instance._get_tick(major=self._major)
581-
# Re-apply any ``set_tick_params`` overrides to the fresh Tick.
582-
# Subclasses of ``Axis`` (e.g. the ``SkewXAxis`` in the skewt
583-
# gallery example) sometimes override ``_get_tick`` without
584-
# forwarding ``_{major,minor}_tick_kw``; calling ``_apply_params``
585-
# here guarantees those overrides still take effect, matching the
586-
# pre-lazy behaviour where the first tick was materialized eagerly
587-
# and updated in place by ``set_tick_params``.
582+
# Re-apply any set_tick_params() overrides to the fresh Tick.
583+
# Subclasses of Axis (e.g. the SkewXAxis in the skewt gallery
584+
# example) sometimes override _get_tick() without forwarding
585+
# _{major,minor}_tick_kw; calling _apply_params() here guarantees
586+
# those overrides still take effect, matching the pre-lazy
587+
# behaviour where the first tick was materialized eagerly and
588+
# updated in place by set_tick_params().
588589
tick_kw = (instance._major_tick_kw if self._major
589590
else instance._minor_tick_kw)
590591
if tick_kw:
@@ -696,14 +697,14 @@ def __init__(self, axes, *, pickradius=15, clear=True):
696697
# Initialize here for testing; later add API
697698
self._major_tick_kw = dict()
698699
self._minor_tick_kw = dict()
699-
# Snapshot of rcParams at the time of the last ``Axis.clear`` (or
700-
# ``set_tick_params(reset=True)``). ``_LazyTickList`` re-applies
701-
# these when it lazily creates a Tick so that the Tick and its
700+
# Snapshot of rcParams at the time of the last Axis.clear() (or
701+
# set_tick_params(reset=True)). _LazyTickList re-applies these
702+
# when it lazily creates a Tick so that the Tick and its
702703
# sub-artists see the same rcParams an eager (pre-lazy)
703704
# 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.
705+
# _major_tick_kw/_minor_tick_kw, which hold user-provided
706+
# set_tick_params() overrides rather than ambient rcParams. See
707+
# _propagate_axis_state_to_tick() for the clip-state counterpart.
707708
self._tick_rcParams = None
708709

709710
if clear:
@@ -883,13 +884,12 @@ def _propagate_axis_state_to_tick(self, tick):
883884
"""
884885
Copy Axis clip state onto a lazily-created Tick.
885886
886-
`Axis.set_clip_path` runs during ``Axes.__clear`` before any Tick
887-
exists under the lazy-init refactor, so the clip stored on the
888-
Axis must be re-stamped onto the first Tick when it materializes
889-
(only the Tick itself and its gridline are clipped, matching
890-
`Tick.set_clip_path`). Per-Artist rcParams like ``path.sketch`` /
891-
``path.effects`` are handled by the ``rc_context`` wrapping in
892-
`_LazyTickList.__get__`, not here.
887+
`Axis.set_clip_path` can run before any Tick exists, so the clip
888+
stored on the Axis must be re-stamped onto the first Tick when
889+
it materializes (only the Tick itself and its gridline are
890+
clipped, matching `Tick.set_clip_path`). Per-Artist rcParams
891+
like ``path.sketch`` / ``path.effects`` are handled by the
892+
rcParams restore in `_LazyTickList.__get__`, not here.
893893
"""
894894
for artist in (tick, tick.gridline):
895895
artist.clipbox = self.clipbox
@@ -940,8 +940,8 @@ def clear(self):
940940
self.callbacks = cbook.CallbackRegistry(signals=["units"])
941941

942942
# Snapshot current rcParams so that a Tick materialized later by
943-
# ``_LazyTickList`` (possibly outside any ``rc_context`` active
944-
# now) sees the same rcParams an eager pre-lazy tick would have.
943+
# _LazyTickList (possibly outside any rc_context() active now)
944+
# sees the same rcParams an eager pre-lazy tick would have.
945945
self._tick_rcParams = dict(mpl.rcParams)
946946

947947
# whether the grids are on

0 commit comments

Comments
 (0)