FIX: Lock axes bounds in plot_joint to prevent shrinking on cursor motion (closes #14317) - #14319
Open
AkhilG-exe wants to merge 1 commit into
Open
AkhilG-exe wants to merge 1 commit into
AkhilG-exe wants to merge 1 commit into
Conversation
…tion (mne-tools#14317) The ConnectionPatch lines between the time series and topomaps are not clipped to the timeseries axes, so matplotlib constrained layout counts their extent in the axes margins on every draw. The measured margin grows monotonically, shrinking the axes to zero on each redraw (which cursor motion triggers). Mark the connection lines as out-of-layout (set_in_layout(False)) so the layout ignores them.
AkhilG-exe
requested review from
agramfort,
drammock and
larsoner
as code owners
September 19, 2026 22:36
CarinaFo
approved these changes
Sep 20, 2026
CarinaFo
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the quick bugfix, looks good. I verified the bug and the fix on Windows 11.
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.
Why
evoked.plot_joint()figures shrink to zero once the cursor moves (or hovers) over them (closes #14317).The joint plot is a
layout="constrained"figure. The connection lines between the time series and the topomaps are drawn asConnectionPatch(..., clip_on=False)artists added to the butterfly (ts_ax) axes. Matplotlib's constrained layout computes each axes' margins fromAxes.get_tightbbox(for_layout_only=True), which includes every artist not fully clipped to the axes. Because these lines poke outsidets_axand never move with it, every redraw (which cursor motion triggers through the interactive hover/_BlitManagerpath) measures a larger margin than the last, and the solver turns that growth back into a smaller axes — a feedback loop collapsing all axes to zero.Reproduces with a plain sequence of
fig.canvas.draw()calls:What
mne/viz/evoked.py: callcon.set_in_layout(False)on the connection lines so constrained layout ignores them. This is the matplotlib-idiomatic mechanism for artists that intentionally leave their axes; rendering is unchanged and the initial layout is essentially the same.mne/viz/tests/test_topo.py: regression assertions added to the existingtest_plot_joint— the largest axes' position must be unchanged after repeated redraws.doc/changes/dev/14319.bugfix.rst: changelog fragment.doc/changes/names.inc: new contributor entry.Test plan
pytest mne/viz/tests/test_topo.py mne/viz/tests/test_evoked.py→ 25 passedtest_plot_jointfails without the fix (regression) and passes with itTFR joint-plot tests (
test_tfr_plot_joint,test_tfr_plot_joint_doesnt_modify) → 16 passed (TFR path was already safe: itsConnectionPatchis attached to the figure, not an axes)ruff check/ruff format --checkclean on modified filesBefore/after visual verification: pre-fix renders drift by 122,985 pixels over 9 redraws; post-fix renders are bit-identical (0 pixels).
Disclosure per the AI-assistance policy: this change was developed with assistance from an AI coding agent (opencode), which diagnosed the constrained-layout feedback loop, while I implemented the one-line fix, and drafted the regression test. I reviewed and verified all changes. as well.