diff --git a/doc/changes/dev/13795.other.rst b/doc/changes/dev/13795.other.rst new file mode 100644 index 00000000000..5c07b2477b8 --- /dev/null +++ b/doc/changes/dev/13795.other.rst @@ -0,0 +1 @@ +Made :meth:`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`, by `Pragnya Khandelwal`_. diff --git a/mne/viz/_mpl_figure.py b/mne/viz/_mpl_figure.py index 47a26047768..ac1b66a18b3 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 """ @@ -2378,7 +2378,10 @@ def _line_figure(inst, axes=None, picks=None, **kwargs): # if picks is None, only show data channels allowed_ch_types = _DATA_CH_TYPES_SPLIT if picks is None else _VALID_CHANNEL_TYPES # figure out expected number of axes - ch_types = np.array(inst.get_channel_types()) + try: + ch_types = np.array(inst.get_channel_types()) + except AttributeError: + ch_types = np.array(inst.info.get_channel_types()) if picks is not None: ch_types = ch_types[picks] n_axes = len(np.intersect1d(ch_types, allowed_ch_types)) 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 diff --git a/tutorials/evoked/10_evoked_overview.py b/tutorials/evoked/10_evoked_overview.py index b251a1f8239..52d440c7f9f 100644 --- a/tutorials/evoked/10_evoked_overview.py +++ b/tutorials/evoked/10_evoked_overview.py @@ -71,7 +71,7 @@ # # We can visualize the average evoked response for left-auditory stimuli using # the :meth:`~mne.Evoked.plot` method, which yields a butterfly plot of each -# channel type: +# channel type (interactive butterfly figure): evoked.plot()