Skip to content

Chore: refactor figure with new subplot manager (#698)#759

Merged
cvanelteren merged 2 commits into
mainfrom
v3.0
Jul 14, 2026
Merged

Chore: refactor figure with new subplot manager (#698)#759
cvanelteren merged 2 commits into
mainfrom
v3.0

Conversation

@cvanelteren

Copy link
Copy Markdown
Collaborator

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).

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).
@cvanelteren cvanelteren marked this pull request as ready for review July 14, 2026 03:07
@cvanelteren cvanelteren merged commit d542870 into main Jul 14, 2026
2 of 4 checks passed
@cvanelteren cvanelteren deleted the v3.0 branch July 14, 2026 03:08
@cvanelteren

Copy link
Copy Markdown
Collaborator Author

Closing the v3.0 branch as it only contained this change anyway.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.89579% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/_subplots.py 93.92% 4 Missing and 9 partials ⚠️
ultraplot/figure.py 94.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant