diff --git a/doc/changes/dev/14319.bugfix.rst b/doc/changes/dev/14319.bugfix.rst new file mode 100644 index 00000000000..91191e9a80e --- /dev/null +++ b/doc/changes/dev/14319.bugfix.rst @@ -0,0 +1 @@ +Fix :meth:`mne.Evoked.plot_joint` interactive plots, where the axes shrank to zero when moving the cursor over the figure (the connection lines between the time series and topomaps were inflating the constrained layout, shrinking the axes on every redraw), by `Akhil Gopu`_. \ No newline at end of file diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 2c6f8fa77cd..e73278e2258 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -5,6 +5,7 @@ .. _Adeline Fecker: https://github.com/adelinefecker .. _Adina Wagner: https://github.com/adswa .. _Adonay Nunes: https://github.com/AdoNunes +.. _Akhil Gopu: https://github.com/AkhilG-exe .. _Akhilesh S. Yadav: https://github.com/YadavAkhileshh .. _Akshay: https://github.com/Akshay0724 .. _Alan Leggitt: https://github.com/leggitta diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 5707da73ec2..4dbddab83e3 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -2372,6 +2372,10 @@ def plot_evoked_joint( zorder=1, clip_on=False, ) + # The lines intentionally poke outside of `ts_ax`, so keep them out of the + # layout bbox reckoning; otherwise constrained layout grows the margin on + # every redraw, shrinking the axes to nothing (see #14317). + con.set_in_layout(False) ts_ax.add_artist(con) # mark times in time series plot diff --git a/mne/viz/tests/test_topo.py b/mne/viz/tests/test_topo.py index 24439626764..64705a61c80 100644 --- a/mne/viz/tests/test_topo.py +++ b/mne/viz/tests/test_topo.py @@ -79,7 +79,15 @@ def _get_epochs_delayed_ssp(): def test_plot_joint(): """Test joint plot.""" evoked = _get_epochs().average() - evoked.plot_joint(ts_args=dict(time_unit="s"), topomap_args=dict(time_unit="s")) + fig = evoked.plot_joint( + picks="grad", ts_args=dict(time_unit="s"), topomap_args=dict(time_unit="s") + ) + ax = max(fig.axes, key=lambda a: a.get_position().height) + fig.canvas.draw() + pos = ax.get_position().bounds + for _ in range(5): + fig.canvas.draw() + assert np.allclose(pos, ax.get_position().bounds) def return_inds(d): # to test function kwarg to zorder arg of evoked.plot return list(range(d.shape[0]))