Chore: refactor figure with new subplot manager (#698)#759
Merged
Conversation
Move subplot creation, gridspec ownership, and projection parsing out of `Figure` and into a dedicated `SubplotManager` (`ultraplot/_subplots.py`), a first step toward treating `Figure` as an interface that delegates to focused collaborators rather than a monolith (partially addresses #677). The public API is unchanged: the former `_subplot_dict`, `_subplot_counter` and `_gridspec` attributes now live on the manager and are reached through the new `Figure._get_subplot()` / `Figure._iter_subplots()` accessors and the existing `Figure.gridspec` property, with call sites in `gridspec.py` and `axes/base.py` going through those instead of touching figure internals. Also fixes projection keywords being dropped by `uplt.subplot()`: `ui.subplot` introspects the signature of `Figure._parse_proj` to decide which keywords belong to the subplot rather than the figure, so that signature must stay spelled out rather than collapsing into `**kwargs`. Adds `ultraplot/tests/test_subplot_manager.py` covering subplot creation, the gridspec setter, projection resolution (native, external-container, and geographic), per-axes projection arguments, and the `ui.subplot`/`subplots` keyword routing. Follow-ups filed: #755 (signature coupling in `ui.py`), #756 (`Figure.clear` leaves stale subplot state), #757 (`SubplotManager`/`Figure` coupling), #758 (dead imports).
Collaborator
Author
|
Closing the v3.0 branch as it only contained this change anyway. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Move subplot creation, gridspec ownership, and projection parsing out of
Figureand into a dedicatedSubplotManager(ultraplot/_subplots.py), a first step toward treatingFigureas an interface that delegates to focused collaborators rather than a monolith (partially addresses #677). The public API is unchanged: the former_subplot_dict,_subplot_counterand_gridspecattributes now live on the manager and are reached through the newFigure._get_subplot()/Figure._iter_subplots()accessors and the existingFigure.gridspecproperty, with call sites ingridspec.pyandaxes/base.pygoing through those instead of touching figure internals. Also fixes projection keywords being dropped byuplt.subplot():ui.subplotintrospects the signature ofFigure._parse_projto decide which keywords belong to the subplot rather than the figure, so that signature must stay spelled out rather than collapsing into**kwargs. Addsultraplot/tests/test_subplot_manager.pycovering subplot creation, the gridspec setter, projection resolution (native, external-container, and geographic), per-axes projection arguments, and theui.subplot/subplotskeyword routing. Follow-ups filed: #755 (signature coupling inui.py), #756 (Figure.clearleaves stale subplot state), #757 (SubplotManager/Figurecoupling), #758 (dead imports).