From a3460b2621a0e59a9163263c58982e08ac1031ae Mon Sep 17 00:00:00 2001 From: PragnyaKhandelwal Date: Sun, 29 Mar 2026 11:00:14 +0530 Subject: [PATCH 1/3] VIZ: route evoked.plot() through MNELineFigure for default path When evoked.plot() creates its own figure (axes=None), now routes through _line_figure() to instantiate MNELineFigure instead of a plain matplotlib figure. This aligns with the 2D plotting figure-class refactor direction discussed in #7751. Behavior unchanged for custom axes. Both plot_white() and plot_joint() remain out of scope here. Adds regression test to assert MNELineFigure instantiation for default path. Closes #13747 --- doc/changes/dev/13747.newfeature.rst | 1 + mne/viz/_mpl_figure.py | 2 +- mne/viz/evoked.py | 17 +++++++++++++---- mne/viz/tests/test_evoked.py | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 doc/changes/dev/13747.newfeature.rst diff --git a/doc/changes/dev/13747.newfeature.rst b/doc/changes/dev/13747.newfeature.rst new file mode 100644 index 00000000000..fa885e7c9a3 --- /dev/null +++ b/doc/changes/dev/13747.newfeature.rst @@ -0,0 +1 @@ +Made ``evoked.plot()`` instantiate ``MNELineFigure`` when it creates its own figure, aligning this path with the ongoing 2D plotting figure-class refactor discussed in :gh:`7751`. diff --git a/mne/viz/_mpl_figure.py b/mne/viz/_mpl_figure.py index 47a26047768..4d33091e581 100644 --- a/mne/viz/_mpl_figure.py +++ b/mne/viz/_mpl_figure.py @@ -26,7 +26,7 @@ └ MNELineFigure Interactive figure for non-scrollable data. Generated by: - spectrum.plot() - - evoked.plot() TODO Not yet implemented + - evoked.plot() - evoked.plot_white() TODO Not yet implemented - evoked.plot_joint() TODO Not yet implemented """ diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index a62d2379f03..ecd029980cd 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -452,10 +452,19 @@ def _plot_evoked( fig = None if axes is None: - fig, axes = plt.subplots(len(ch_types_used), 1, layout="constrained") - if isinstance(axes, plt.Axes): - axes = [axes] - fig.set_size_inches(6.4, 2 + len(axes)) + if plot_type == "butterfly": + from ._mpl_figure import _line_figure + + fig, axes = _line_figure( + evoked, + picks=picks, + figsize=(6.4, 2 + len(ch_types_used)), + ) + else: + fig, axes = plt.subplots(len(ch_types_used), 1, layout="constrained") + if isinstance(axes, plt.Axes): + axes = [axes] + fig.set_size_inches(6.4, 2 + len(axes)) if isinstance(axes, plt.Axes): axes = [axes] diff --git a/mne/viz/tests/test_evoked.py b/mne/viz/tests/test_evoked.py index 9071bb8971c..8698cf525d8 100644 --- a/mne/viz/tests/test_evoked.py +++ b/mne/viz/tests/test_evoked.py @@ -126,6 +126,7 @@ def test_plot_evoked(): fig = evoked.plot( proj=True, hline=[1], exclude=[], window_title="foo", time_unit="s" ) + assert fig.__class__.__name__ == "MNELineFigure" amplitudes = _get_amplitudes(fig) assert len(amplitudes) == len(default_picks) assert evoked.proj is False From 83ba4caceb4324e4af70eab2cbd4dbdb6b6fbb44 Mon Sep 17 00:00:00 2001 From: PragnyaKhandelwal Date: Sun, 29 Mar 2026 13:01:54 +0530 Subject: [PATCH 2/3] MAINT: rename towncrier fragment for PR #13795 --- doc/changes/dev/{13747.newfeature.rst => 13795.newfeature.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/changes/dev/{13747.newfeature.rst => 13795.newfeature.rst} (100%) diff --git a/doc/changes/dev/13747.newfeature.rst b/doc/changes/dev/13795.newfeature.rst similarity index 100% rename from doc/changes/dev/13747.newfeature.rst rename to doc/changes/dev/13795.newfeature.rst From 18724394d6719fa563e1003822bb051611938c58 Mon Sep 17 00:00:00 2001 From: PragnyaKhandelwal Date: Sun, 29 Mar 2026 13:16:38 +0530 Subject: [PATCH 3/3] FIX: keep dipole plotting on legacy figure path --- mne/viz/evoked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index ecd029980cd..92600884fb2 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -452,7 +452,7 @@ def _plot_evoked( fig = None if axes is None: - if plot_type == "butterfly": + if plot_type == "butterfly" and hasattr(evoked, "get_channel_types"): from ._mpl_figure import _line_figure fig, axes = _line_figure(