Chore: refactor figure with new subplot manager#698
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
cvanelteren
marked this pull request as draft
April 20, 2026 03:47
cvanelteren
marked this pull request as ready for review
April 22, 2026 04:39
Figure._parse_proj had been reduced to a (*args, **kwargs) passthrough to
SubplotManager. That signature is introspected, not just called: ui.subplot
runs _pop_params over it to decide which keywords belong to the subplot
rather than the figure. With the named parameters gone, proj, projection,
proj_kw, projection_kw, backend and basemap were routed to the figure
instead, so uplt.subplot(proj="polar") raised
AttributeError: Figure.set() got an unexpected keyword argument 'proj'
Spell the parameters out again and forward them by name. uplt.subplots was
unaffected only because _add_subplots kept its explicit signature.
Also in _subplots.py: drop the unused inspect and typing imports, resolve
the Figure annotation under TYPE_CHECKING, use super() instead of naming
matplotlib's Figure so a mixin in a subclass MRO is not skipped, and remove
the dead isinstance(figure, Axes) branches (a Figure is never an Axes).
Cover the ui.subplot/ui.subplots projection paths, which no test exercised,
and tighten the manager tests that only asserted "is not None" or len(axs)
so they can actually fail. Note that the external-container test must use a
projection cartopy does not also know, or it resolves to a GeoAxes instead.
This was referenced Jul 14, 2026
Closed
cvanelteren
added a commit
that referenced
this pull request
Jul 14, 2026
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).
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.
Partially addresses #677
This PR marks one of the first changes behind the scenes for the
Figureclass. The idea is to useFiguremore as an interface with clear separation of tasks and responsibility. This will change the monolith it is today to better mangeable code that can be edited, expanded, and easier contributed to.