Skip to content

Add InsetAxes for floating overlay sub-plots#6

Merged
CSSFrancis merged 5 commits intomainfrom
inset-plot
Apr 20, 2026
Merged

Add InsetAxes for floating overlay sub-plots#6
CSSFrancis merged 5 commits intomainfrom
inset-plot

Conversation

@CSSFrancis
Copy link
Copy Markdown
Owner

This adds InsetAxes with the idea that you can have floating subplots. Mostly this is a way to handle things like:

https://www.pyxem.org/en/stable/examples/orientation_mapping/multi_phase_orientation.html#sphx-glr-examples-orientation-mapping-multi-phase-orientation-py

The axes can be toggled and have a title. Otherwise they are a functionaly Plot object and cna have things like markers etc, as well as handle things like events. For the example above I'd like to be able to select an orientation --> Display just that orientation as an overlay.

I also added in a change log with towncrier for tracking changes.

@CSSFrancis CSSFrancis requested a review from Copilot April 20, 2026 02:34
@CSSFrancis CSSFrancis merged commit 9fe0347 into main Apr 20, 2026
13 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new InsetAxes concept to allow “floating” overlay subplots that sit above the main figure grid, and adds release/changelog infrastructure based on towncrier.

Changes:

  • Added InsetAxes plus Figure.add_inset() and layout serialization (inset_specs) + event handling for inset state changes.
  • Added tests for inset behavior and new pixel-level visual regression harness.
  • Added towncrier configuration, upcoming-changes fragments, changelog scaffolding, and release/prepare-release GitHub workflows.

Reviewed changes

Copilot reviewed 14 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
upcoming_changes/README.rst Contributor guidance for towncrier fragment-based changelog entries.
upcoming_changes/6.new_feature.rst Towncrier fragment announcing InsetAxes feature.
tests/test_interaction.py Updates coordinate math/comments for scaled 2D overlay tests.
tests/test_inset_visual.py Adds visual regression tests for inset rendering/states.
tests/test_inset.py Adds unit tests for inset creation, layout JSON, stacking, state transitions, and event handling.
tests/baselines/plot1d_sine.png Adds baseline image used by visual regression tests.
tests/baselines/plot1d_markers.png Adds baseline image used by visual regression tests.
tests/baselines/plot1d_dashed.png Adds baseline image used by visual regression tests.
tests/baselines/plot1d_alpha.png Adds baseline image used by visual regression tests.
tests/baselines/pcolormesh_uniform.png Adds baseline image used by visual regression tests.
tests/baselines/imshow_viridis.png Adds baseline image used by visual regression tests.
tests/baselines/imshow_gradient.png Adds baseline image used by visual regression tests.
tests/baselines/imshow_checkerboard.png Adds baseline image used by visual regression tests.
tests/baselines/bar_basic.png Adds baseline image used by visual regression tests.
pyproject.toml Adds towncrier dev dependency and [tool.towncrier] configuration.
docs/api/figure_plots.rst Documents InsetAxes in the API docs.
anyplotlib/figure_plots.py Implements InsetAxes and adds shared _plot_kind() for layout serialization.
anyplotlib/figure.py Adds inset plumbing: add_inset(), inset registration/map, inset layout serialization, and inset state event handling.
anyplotlib/__init__.py Exposes InsetAxes at the package top level.
CHANGELOG.rst Adds towncrier-managed changelog scaffold with initial release entry.
.github/workflows/release.yml Adds tag-triggered build/publish/release workflow.
.github/workflows/prepare_release.yml Adds manual workflow to bump versions, build changelog via towncrier, and open a release PR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3483 to +3496
def __init__(self, fig, w_frac: float, h_frac: float, *,
corner: str = "top-right", title: str = ""):
if corner not in _VALID_CORNERS:
raise ValueError(
f"corner must be one of {_VALID_CORNERS!r}, got {corner!r}"
)
# Pass a dummy SubplotSpec so Axes.__init__ doesn't fail — InsetAxes
# never occupies a grid cell, only overlays the figure.
super().__init__(fig, SubplotSpec(None, 0, 1, 0, 1))
self.w_frac = w_frac
self.h_frac = h_frac
self.corner = corner
self.title = title
self._inset_state: str = "normal"
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InsetAxes documents w_frac/h_frac as 0–1 fractions of the figure size, but the constructor does not validate these values. Passing negative numbers, 0, NaN, or >1 will flow into Figure._push_layout() and produce invalid/huge panel sizes or JS layout issues. Consider validating that both are finite floats in (0, 1] (or whatever range you intend) and raising ValueError with a clear message.

Copilot uses AI. Check for mistakes.
pytest.skip(f"Baseline updated: {path.name}")

if not path.exists():
pytest.skip(
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These visual-regression tests will be skipped in CI if the corresponding baseline PNGs are not present. This PR adds no inset_*.png baselines, so all the new inset visual tests will currently skip and won’t provide regression protection. Consider committing the required baseline images (or making the tests fail when baselines are missing, depending on your intended workflow).

Suggested change
pytest.skip(
pytest.fail(

Copilot uses AI. Check for mistakes.
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.

2 participants