Skip to content

fix: make plot_array overlays respect imshow_origin "lower" (#565) - #616

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/imshow-origin-lower-overlays
Oct 7, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/imshow-origin-lower-overlays

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Fixes #565 — community report by @ClarkGuilty, Discussion #14.

With visualize/general.yaml -> imshow_origin: lower, plot_array reflected the image raster about the extent's y midpoint but drew every vector overlay (mask edge, border, origin marker, grid, mesh grid, positions, lines, regions, quiver vectors) in unreflected data coordinates. The figure still looked plausible, so critical curves and caustics silently slid off the arcs they belong to.

The fix follows the pattern _apply_contours already used: two private helpers in autoarray/plot/utils.py reflect overlay y about the raster extent's midpoint when the origin is "lower" (_overlay_yx_for_origin, and _vector_yx_for_origin which also negates dy for quiver rows). plot_array passes every overlay through them before drawing; "upper" is byte-for-byte unchanged. The same audit found the uniform rectangular mesh path of plot_inversion_reconstruction (an imshow honouring the origin) had the identical defect, so _plot_rectangular now returns its raster extent and the lines/regions/grid overlays are reflected there too. Patches are drawn as given and documented as not origin-aware. When extent is None matplotlib draws in pixel-index coordinates under either origin, so no reflection is applied.

The imshow_origin config comment now records the caveat from the report: the setting is presentation only, and under lower the displayed y axis and reported model y parameters disagree in sign.

API Changes

None. Both helpers are private; the config key, its default and every public plot_* signature are unchanged. User-visible behaviour change: with imshow_origin: lower, overlays now land on the image features they describe.

Test Plan

  • New test_autoarray/plot/test_array.py: three origin-agnostic regression tests (positions marker, asymmetric polyline, uniform-mesh inversion grid), each parametrised over upper / lower. They read the drawn overlay back from the axes, map it through the image's own extent and origin, and assert the array is bright there — so they keep passing under any correct fix rather than pinning today's layout. Red on unfixed main for every lower case (assert 0.0 == 1.0), green now.
  • python -m pytest test_autoarray/plot/ — 41 passed
  • python -m pytest test_autoarray/ — 1981 passed, 4 xfailed
  • CI matrix (3.12 / 3.13)

Known remaining lower quirk, out of scope: zoom_to_brightest in plot_inversion_reconstruction sets axis limits from an unreflected zoom extent, so on a uniform mesh under lower the zoom window can sit over the wrong part of the image. Pre-existing; noted on #565.

Full API Changes (for automation & release notes)

Added

  • autoarray.plot.utils._overlay_yx_for_origin(yx, extent, origin_imshow) (private)
  • autoarray.plot.utils._vector_yx_for_origin(vector_yx, extent, origin_imshow) (private)
  • autoarray.plot.inversion._plot_rectangular now returns the raster extent (uniform path) or None (private)

Removed

  • none

Migration

  • none

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

With imshow_origin: lower the raster was reflected about the extent's y
midpoint but every vector overlay (mask edge, border, origin marker, grid,
mesh grid, positions, lines, regions, quiver) stayed in unreflected data
coordinates, so critical curves and caustics silently slid off their arcs.

Add private helpers _overlay_yx_for_origin / _vector_yx_for_origin in
plot/utils.py that reflect overlay y (and negate quiver dy) under "lower",
following the pattern _apply_contours already used, and route every
plot_array overlay through them. The uniform rectangular mesh path of
plot_inversion_reconstruction had the same defect; _plot_rectangular now
returns its raster extent so its overlays are reflected too. "upper" is
unchanged. Patches are documented as not origin-aware.

Add origin-agnostic regression tests (positions, lines, inversion grid)
parametrised over both origins, red on unfixed main for every "lower" case.
Document on the config key that imshow_origin is presentation only.

Reported by @ClarkGuilty in PyAutoLabs Discussion #14, including the
reproducer and the regression-test design.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 34c2e83 into main Oct 7, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/imshow-origin-lower-overlays branch October 7, 2026 08:47
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.

fix: make plot_array overlays respect imshow_origin

1 participant