Skip to content

VIZ: evoked.plot() still bypasses MNELineFigure path (related to #7751) #13747

@PragnyaKhandelwal

Description

@PragnyaKhandelwal

Describe the new feature or enhancement

I was investigating a small plotting behavior detail and traced figure-creation paths in mne/viz/_mpl_figure.py and mne/viz/evoked.py.

During that check, I noticed that evoked.plot() still creates a plain Matplotlib figure in its default path, even though the line-plot figure-class refactor direction in #7751 points toward consolidating these under MNELineFigure.

A small, isolated enhancement would be to:

  • route evoked.plot() through _line_figure / MNELineFigure when it creates its own figure
  • keep plot_white / plot_joint out of scope for now
  • add a small regression test to lock this behavior

I can open a focused PR as a partial improvement linked to #7751, without claiming closure of #7751.

Describe your proposed implementation

I propose implementing this as a small enhancement to the existing evoked.plot() path in mne/viz/evoked.py:

  • when evoked.plot() creates its own figure (axes is None), route figure creation through mne.viz._mpl_figure._line_figure(...)
  • this makes it instantiate MNELineFigure instead of a plain matplotlib figure for the default path
  • keep behavior unchanged when users pass explicit axes
  • keep evoked.plot_white() and evoked.plot_joint() out of scope for this issue/PR
  • add a regression test in mne/viz/tests/test_evoked.py to assert the expected figure class for evoked.plot() in the default path
  • add a small changelog (towncrier) entry

This keeps the change isolated and aligned with the 2D plotting figure-class refactor direction discussed in #7751.

Describe possible alternatives

Possible alternatives considered:

  1. Do nothing for now
  • Pros: no immediate code churn
  • Cons: evoked.plot() remains inconsistent with the line-figure refactor direction
  1. Refactor evoked.plot(), evoked.plot_white(), and evoked.plot_joint() together in one PR
  • Pros: broader consistency in one go
  • Cons: much larger risk/scope; harder review; more likely to regress behavior
  1. Add a new optional argument (e.g., figure_class="line") to evoked.plot()
  • Pros: explicit opt-in
  • Cons: adds API surface for what should be an internal consistency improvement

Chosen approach (small internal routing change for default evoked.plot()) is better because it is minimal, testable, and incremental, while still moving toward #7751.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions