Repository navigation
Conversation
Add tests for previously untested functionality that operates on all ticks of an Axis: grid toggling via key presses, `Axis.get_ticks_direction`, `Axis.get_tick_padding`, and the label alignment when dragging polar r-labels. These pass with the existing implementation and serve as a safety net for the subsequent refactoring of tick handling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add an internal `_TickGroup` class (one per Axis for major and minor ticks) that bundles all operations on the set of ticks, and route internal code through it instead of looping over individual `Tick` objects. This isolates the internal usage from the tick representation (currently lists of `Tick`), as a first step towards a more efficient collection-based implementation; see matplotlib#5665. This is a pure refactoring without behavior change. The tick lists are still stored in `Axis.majorTicks`/`Axis.minorTicks`, and subclass hooks (`get_major_ticks`, `get_minor_ticks`, `_get_tick`, `_copy_tick_props`) are still honored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
Per #5665, tick management is a substantial cost factor with the potential for large performance gains. Changes are complicated because (1) many details of the ticks are publically exposed and (2) tick management is complicated and scattered thoughout axis.py - i.e. we already try to lazily instantiate, copy some state etc.
In #5665 (comment) I outlined a way how we can get out of this mess.
This PR implements steps
_TickGrouparound the ticks and provide operations to work on all ticks at once andWhile the code change looks substantial, it's actually a pure straight forward refactoring:
_TickGroup; you'll find most sippets moved almost 1:1._TickGroupdoes not own tick-related state (yet). Tick storage stays in majorTicks/minorTicks.Some notable properties:
Why is this reaonable / what's next?
With all tick operations aggregated in
TickGroupI plan to investigate optimization potentials (step 3+4 in #5665 (comment)). What exactly is still to be seen, could e.g. be collections, or "lightweight" Artists with shared properties or just lazily created Artists (each tick consists of 3 Line2D and 2 Text objects and a substantial part of them is often unused).But even if we don't optimize, this refactoring is already a win. The tick management responsibility was spread throughout the whole Axis class (and even beyond - see the backend_bases change here). Collecting them in one class and giving the operations clear names substantially improves architecture and ability to reason about the code.
AI Disclosure
Claude Code (Claude Opus 5.5) was used to profile tick creation, to look through the existing per-tick code paths, and to draft the
_TickGroupimplementation and the new tests, based on the design I outlined in #5665. I reviewed and adjusted the code.PR quality check