Skip to content
Merged
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/14076.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix figures not being displayed in notebook-style frontends when using a Matplotlib inline backend, by `Mingjian He`_.
19 changes: 19 additions & 0 deletions mne/viz/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
centers_to_edges,
compare_fiff,
concatenate_images,
plt_show,
)

base_dir = Path(__file__).parents[2] / "io" / "tests" / "data"
Expand All @@ -46,6 +47,24 @@ def test_setup_vmin_vmax_warns():
_setup_vmin_vmax(data=[-1, 0], vmin=None, vmax=None, norm=True)


@pytest.mark.parametrize(
("backend", "expected"),
(("module://Matplotlib_Inline.backend_inline", "pyplot"), ("QtAgg", "figure")),
)
def test_plt_show_backend(monkeypatch, backend, expected):
"""Test backend-specific show paths."""
calls = []

class Figure:
def show(self, **kwargs):
calls.append(("figure", kwargs))

monkeypatch.setattr("matplotlib.get_backend", lambda: backend)
monkeypatch.setattr(plt, "show", lambda **kwargs: calls.append(("pyplot", kwargs)))
plt_show(fig=Figure(), block=True)
assert calls == [(expected, {"block": True})]


def test_get_color_list():
"""Test getting a colormap from rcParams."""
with rc_context({"axes.prop_cycle": cycler(color=["#ff0000", "#00ff00"])}):
Expand Down
7 changes: 6 additions & 1 deletion mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ def plt_show(show=True, fig=None, **kwargs):
backend = get_backend()
if show and backend != "agg":
logger.debug(f"Showing plot for backend {repr(backend)}")
(fig or plt).show(**kwargs)
# if backend is inline and therefore non-interactive,
# fig.show() fails with UserWarning. See gh-14076
if "inline" in str(backend).lower():
Comment thread
mh105 marked this conversation as resolved.
plt.show(**kwargs)
else:
(fig or plt).show(**kwargs)


def _show_browser(show=True, block=True, fig=None, **kwargs):
Expand Down
Loading