Skip to content

Make blocking consistent#14098

Open
cbrnr wants to merge 2 commits into
mne-tools:mainfrom
cbrnr:mpl-block
Open

Make blocking consistent#14098
cbrnr wants to merge 2 commits into
mne-tools:mainfrom
cbrnr:mpl-block

Conversation

@cbrnr

@cbrnr cbrnr commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #13955.

Here's what I changed to make the blocking behavior consistent:

  • plot_evoked_topomap: removed hardcoded block=False (so this is now consistent with other plotting functions).
  • plot_sensors (plus corresponding methods): changed block=False to block=None (here the argument is useful to force blocking when needed for kind="select").
  • Spectrum.plot_topo, plot_psd_topo methods, plot_raw_psd_topo: deprecated the block argument since I don't think these functions need it.

So the behavior now is as follows: Since show=True by default, this essentially means that the functions call plt.show() internally. This shows the figure and blocks by default. Blocking can be changed via %matplotlib in IPython or plt.ion() in the regular Python REPL. I'm not sure about Jupyter notebooks, but I think whatever they do shouldn't have changed (they probably do not block by default).

@cbrnr
cbrnr requested review from agramfort and larsoner as code owners July 24, 2026 10:27
@cbrnr
cbrnr requested a review from wmvanvliet July 24, 2026 10:28

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay for me, @drammock did you want to look?

@@ -0,0 +1 @@
The ``block`` parameter of :meth:`mne.time_frequency.Spectrum.plot_topo`, the legacy ``plot_psd_topo`` methods (e.g. :meth:`mne.io.Raw.plot_psd_topo`), and :func:`mne.viz.plot_raw_psd_topo` is deprecated and will be removed in MNE 1.15; these plots now follow Matplotlib's blocking behavior, by `Clemens Brunner`_.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CircleCI doesn't like that link

/home/circleci/project/doc/<rst_prologue>:75: WARNING: py:func reference target not found: mne.viz.plot_raw_psd_topo [ref.func]

%(axis_facecolor)s
%(axes_spectrum_plot_topo)s
%(block)s
block : bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
block : bool
block : bool | None

Comment thread mne/utils/docs.py
Show the figure if ``True``. When shown, blocking follows
:func:`matplotlib.pyplot.show`: the call blocks until the window is closed unless
Matplotlib's interactive mode is on (enabled with :func:`matplotlib.pyplot.ion`,
which IPython's Matplotlib integration turns on automatically), in which case it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is misleading/ambiguous; it could be interpreted to mean that IPython automatically enables plt.ion (but it only does that if you use the %matplotlib magic)

Comment thread mne/viz/raw.py
@@ -588,8 +588,8 @@ def plot_raw_psd_topo(
Defaults to black.
%(axes_spectrum_plot_topo)s
block : bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
block : bool
block : bool | None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DISCUSSION] Showing figures when running in non-interactive python: to block or not to block?

3 participants