Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/14098.apichange.rst
Original file line number Diff line number Diff line change
@@ -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`_.
Comment thread
cbrnr marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions doc/changes/dev/14098.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed :func:`~mne.viz.plot_evoked_topomap` and :func:`~mne.viz.plot_sensors` (and the ``plot_sensors`` methods) to follow Matplotlib's blocking behavior when ``show=True`` instead of returning immediately; ``plot_sensors`` keeps its ``block`` argument (default now ``None``), by `Clemens Brunner`_.
15 changes: 11 additions & 4 deletions mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def plot_sensors(
ch_groups=None,
to_sphere=True,
axes=None,
block=False,
block=None,
show=True,
sphere=None,
*,
Expand Down Expand Up @@ -736,11 +736,18 @@ def plot_sensors(
instance of Axes3D. If None (default), a new axes will be created.

.. versionadded:: 0.13.0
block : bool
Whether to halt program execution until the figure is closed.
Defaults to False.
block : bool | None
Whether to halt program execution until the figure is closed. By default
(``None``) this follows :func:`matplotlib.pyplot.show`: it blocks unless
Matplotlib's interactive mode is on (see :func:`matplotlib.pyplot.ion`), in
which case it returns immediately. Set to ``True`` to force blocking, which
is useful with ``kind="select"`` to collect the interactive selection
synchronously when interactive mode is on.

.. versionadded:: 0.13.0
.. versionchanged:: 1.13
The default changed from ``False`` to ``None`` (follow
Matplotlib).
show : bool
Show figure if True. Defaults to True.
%(sphere_topomap_auto)s
Expand Down
23 changes: 18 additions & 5 deletions mne/time_frequency/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def plot_psd_topo(
fig_facecolor="k",
axis_facecolor="k",
axes=None,
block=False,
block=None,
show=True,
n_jobs=None,
verbose=None,
Expand All @@ -181,7 +181,9 @@ def plot_psd_topo(
%(fig_facecolor)s
%(axis_facecolor)s
%(axes_spectrum_plot_topo)s
%(block)s
block : bool
This parameter is deprecated and will be removed in MNE 1.15; blocking now
follows Matplotlib's behavior (see ``show``).
%(show)s
%(n_jobs)s
%(verbose)s
Expand Down Expand Up @@ -726,7 +728,7 @@ def plot_topo(
fig_facecolor="k",
axis_facecolor="k",
axes=None,
block=False,
block=None,
show=True,
):
"""Plot power spectral density, separately for each channel.
Expand All @@ -739,7 +741,9 @@ def plot_topo(
%(fig_facecolor)s
%(axis_facecolor)s
%(axes_spectrum_plot_topo)s
%(block)s
block : bool
Comment thread
cbrnr marked this conversation as resolved.
Outdated
This parameter is deprecated and will be removed in MNE 1.15; blocking now
follows Matplotlib's behavior (see ``show``).
%(show)s

Returns
Expand Down Expand Up @@ -777,7 +781,16 @@ def plot_topo(
y_label=y_label,
axes=axes,
)
plt_show(show, block=block)
if block is None:
plt_show(show)
else:
warn(
"The 'block' parameter is deprecated and will be removed in MNE 1.15; "
"blocking now follows Matplotlib's behavior. Pass show=False and call "
"matplotlib.pyplot.show() to control it.",
FutureWarning,
)
plt_show(show, block=block)
return fig

@fill_doc
Expand Down
2 changes: 2 additions & 0 deletions mne/time_frequency/tests/test_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ def test_plot_spectrum(method, output, average, request):
n_bad = sum(same_color(line.get_color(), bad_color) for line in lines)
assert n_bad == 1
spectrum.plot_topo()
with pytest.warns(FutureWarning, match="'block' parameter is deprecated"):
spectrum.plot_topo(block=True)
spectrum.plot_topomap()


Expand Down
8 changes: 7 additions & 1 deletion mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4265,7 +4265,13 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):

docdict["show"] = """\
show : bool
Show the figure if ``True``.
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
Comment thread
cbrnr marked this conversation as resolved.
Outdated
returns immediately. Interactive mode is off by default, so a plain script or REPL
blocks. Pass ``show=False`` to build several figures and display them together with
a single :func:`matplotlib.pyplot.show` call.
"""

docdict["show_names_topomap"] = """
Expand Down
6 changes: 3 additions & 3 deletions mne/viz/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def plot_raw_psd_topo(
fig_facecolor="k",
axis_facecolor="k",
axes=None,
block=False,
block=None,
show=True,
n_jobs=None,
verbose=None,
Expand Down Expand Up @@ -588,8 +588,8 @@ def plot_raw_psd_topo(
Defaults to black.
%(axes_spectrum_plot_topo)s
block : bool
Comment thread
cbrnr marked this conversation as resolved.
Outdated
Whether to halt program execution until the figure is closed.
May not work on all systems / platforms. Defaults to False.
This parameter is deprecated and will be removed in MNE 1.15; blocking now
follows Matplotlib's behavior (see ``show``).
%(show)s
%(n_jobs)s
%(verbose)s
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,7 @@ def plot_evoked_topomap(
interactive_colorbar=True,
single_time_point=False,
)
plt_show(show, block=False)
plt_show(show)
if axes is not None:
fig.canvas.draw()
return fig
Expand Down
14 changes: 10 additions & 4 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ def plot_sensors(
ch_groups=None,
to_sphere=True,
axes=None,
block=False,
block=None,
show=True,
sphere=None,
pointsize=None,
Expand Down Expand Up @@ -992,11 +992,17 @@ def plot_sensors(
%(axes_montage)s

.. versionadded:: 0.13.0
block : bool
Whether to halt program execution until the figure is closed. Defaults
to False.
block : bool | None
Whether to halt program execution until the figure is closed. By default
(``None``) this follows :func:`matplotlib.pyplot.show`: it blocks unless
Matplotlib's interactive mode is on (see :func:`matplotlib.pyplot.ion`), in
which case it returns immediately. Set to ``True`` to force blocking, which is
useful with ``kind="select"`` to collect the interactive selection synchronously
when interactive mode is on.

.. versionadded:: 0.13.0
.. versionchanged:: 1.13
The default changed from ``False`` to ``None`` (follow Matplotlib).
show : bool
Show figure if True. Defaults to True.
%(sphere_topomap_auto)s
Expand Down
Loading