Skip to content

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
mne-tools:mainfrom
AkhilG-exe:fix-joint-plot-shrink
Open

AkhilG-exe wants to merge 1 commit into
mne-tools:mainfrom
AkhilG-exe:fix-joint-plot-shrink

Conversation

@AkhilG-exe

Copy link
Copy Markdown

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 as ConnectionPatch(..., clip_on=False) artists added to the butterfly (ts_ax) axes. Matplotlib's constrained layout computes each axes' margins from Axes.get_tightbbox(for_layout_only=True), which includes every artist not fully clipped to the axes. Because these lines poke outside ts_ax and never move with it, every redraw (which cursor motion triggers through the interactive hover/_BlitManager path) 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:

redraws 1 2 3 10
butterfly axes height (before) 0.481 0.452 0.423 0.003
butterfly axes height (after) 0.507 0.507 0.507 0.507

What

  • mne/viz/evoked.py: call con.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 existing test_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 passed

  • test_plot_joint fails without the fix (regression) and passes with it

  • TFR joint-plot tests (test_tfr_plot_joint, test_tfr_plot_joint_doesnt_modify) → 16 passed (TFR path was already safe: its ConnectionPatch is attached to the figure, not an axes)

  • ruff check / ruff format --check clean on modified files

  • Before/after visual verification: pre-fix renders drift by 122,985 pixels over 9 redraws; post-fix renders are bit-identical (0 pixels).

fix_verification_plot

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.

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

@CarinaFo CarinaFo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the quick bugfix, looks good. I verified the bug and the fix on Windows 11.

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.

BUG: interactive plot axes shrink to zero when moving cursor across plot

2 participants