background axis workflow#7
Merged
Merged
Conversation
Switching between 'Fixed' and 'Moving with axes' background modes went through redraw_same_data -> plot_all -> set_axes_lim, which unconditionally reset axis limits to data bounds and lost the user's current zoom/pan. This made the background appear to snap back to full size when entering Moving mode after zooming in. Capture the per-axis xlim/ylim before redraw and reapply them after, so the visible viewport (and the just-captured _bg_extent in Moving mode) stay in sync across the mode switch. https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
The previous attempt at preserving the viewport went through redraw_same_data -> plot_all -> set_axes_lim, which (with AutoScale on, the default) reset the axes to data bounds and additionally rebuilt the imshow artist. The post-hoc _apply_view did not reliably stick because plot_all's other axis-limit machinery (plotSignals, FFT/Compare, user_lim, etc.) interleaves with the redraw, and the rebuild itself causes a visible "snap to full size" of the background. A mode toggle is purely a state change — there is no need to replot. Tag the bg image artist when it is created so it can be located later, then in onBgModeFixed/onBgModeMoving simply find each axis's tagged image and set its extent (current xlim/ylim for Fixed, captured _bg_extent for Moving), flip _bg_glued, and request a single canvas.draw_idle. The existing xlim_changed/ylim_changed callback is already mode-aware (early-returns while _bg_glued is True), so it correctly keeps the image in sync going forward in either mode. Also unify imshow creation in plot_all so the lim-changed callback is registered in both modes — otherwise reloading data while in Moving mode would create a new artist without the callback, breaking the subsequent switch back to Fixed. https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
Previous fix re-wrote the image artist's extent to the current xlim/ylim on entering Fixed mode. If the user had previously been in Moving mode and zoomed into a sub-region of the background, this collapsed the whole image into the tiny viewport — the user described it as the background "resetting to full size" because the entire image suddenly became visible (squeezed) instead of staying as the magnified portion. Make onBgModeFixed a pure state flip: just set _bg_glued = False (and clear _bg_extent so a future plot rebuild doesn't pin the new artist to the old captured rectangle). The image keeps whatever extent it had, and the existing xlim_changed/ylim_changed callback — now no longer short-circuited by _bg_glued — will start tracking the viewport on the next pan/zoom. Transition is visually invisible at the moment of switch. https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
When the user types limits into the limits panel, they want a specific viewport — not for the background image to follow the new limits. Previously, in Fixed mode (_bg_glued=False), the xlim_changed callback fired during the redraw triggered by onAxisLimitChange and updated the artist's extent to the new viewport, so the bg "moved with" the limits. Snapshot each axis's bg image extent before the redraw and reapply it to the rebuilt artist after. The bg keeps its current visual data-coord position; subsequent toolbar pan/zoom still behaves per-mode (Fixed follows, Moving stays). https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
In Fixed mode the bg image was rendered in data coordinates with a callback that kept its extent equal to the current viewport. As soon as the viewport changed (toolbar zoom, limits panel, autoscale) the bg moved/resized on screen with the data. The user expects Fixed mode to mean "bg pinned to the plot rectangle": whatever portion of the bg was visible at the moment of switching should stay pixel-identical until they change modes again. Render the bg in axes (screen) coordinates via transAxes: - Moving : transData, extent = _bg_extent (unchanged) - Fixed-locked : transAxes, cropped image at _bg_axes_extent - Fixed-default : transAxes, full image at [0,1,0,1] (fresh-loaded bg) Switching Moving -> Fixed snapshots the visible portion of the bg (crop + axes-fraction extent computed from the artist's current data extent and the viewport) and re-creates each artist in transAxes. Any subsequent xlim/ylim change is now independent of the bg by construction. The xlim_changed/ylim_changed callback and the onAxisLimitChange snapshot/restore workaround (commit 4604707) are no longer needed and have been removed. https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
Switching to Moving was rendering the full _bg_image at extent=current viewport, even though the user had been seeing only a cropped portion pinned in Fixed-locked mode. The result was a visible jump (the rest of the bg suddenly reappearing). Compute the new _bg_extent by mapping the prior axes-fraction extent (_bg_axes_extent, or [0,1,0,1] for Fixed-default) into the current viewport's data coords, and render the same image that was just on screen — the cropped image in Fixed-locked mode, the full image in Fixed-default. Both _replace_bg_artists and plot_all's Moving branch now use _bg_display_image when set, falling back to _bg_image. _compute_bg_screen_lock also pulls the source array straight from the existing artist (instead of always self._bg_image) and handles the transAxes case (re-clicking Fixed when already in Fixed-locked) by mapping its axes-fraction extent back to data coords before cropping. https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
After a Fixed -> Moving switch the user could only see the cropped portion of the bg, even when panning, because Moving mode was rendering the cropped image. They want to explore the parts that were outside the prior viewport (axis labels etc.). Track which fraction of the original _bg_image the displayed crop represents (_bg_crop_box). On Fixed -> Moving, use that crop box plus the current axes-fraction extent and viewport to compute a data-coord extent for the FULL _bg_image such that its currently-visible portion lands exactly where the crop was on screen — visually invisible at the moment of switch, but the rest of the bg is now reachable by panning. _compute_bg_screen_lock composes the new crop fractions with the existing _bg_crop_box, so cropping repeatedly across mode switches always stays expressed relative to the original full image. https://claude.ai/code/session_01VfZebri6U3ebhr2fxBbAKK
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.
Enables: