Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/dev/13795.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made :meth:`evoked.plot() <mne.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`_.
7 changes: 5 additions & 2 deletions mne/viz/_mpl_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 13 additions & 4 deletions mne/viz/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions mne/viz/tests/test_evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading