Skip to content

Fix: Handle inline backends in plt_show#14076

Merged
larsoner merged 4 commits into
mne-tools:mainfrom
mh105:agent/upstream-inline-plt-show
Jul 21, 2026
Merged

Fix: Handle inline backends in plt_show#14076
larsoner merged 4 commits into
mne-tools:mainfrom
mh105:agent/upstream-inline-plt-show

Conversation

@mh105

@mh105 mh105 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Reference issue (if any)

None

What does this implement/fix?

mne.viz.utils.plt_show() currently calls Figure.show() when it receives a figure. With a Matplotlib inline backend, that call does not reliably trigger display in notebook-style frontends. This includes the VS Code Interactive Window that some people use. matplotlib.pyplot.show() does.

This change detects inline backend identifiers case-insensitively and routes them through plt.show(**kwargs). Other GUI backends continue to use (fig or plt).show(**kwargs), while the existing no-show behavior for Agg and show=False remains unchanged.

Additional information

I manually identified the issue and implemented the fix, but Codex added the test case to mne/viz/tests/test_utils.py

@mh105
mh105 requested a review from drammock as a code owner July 19, 2026 18:33
@mh105 mh105 changed the title FIX: Handle inline backends in plt_show Fix: Handle inline backends in plt_show Jul 19, 2026
Comment thread mne/viz/utils.py
Add comment regarding fig.show() failure for inline backends.
@larsoner

Copy link
Copy Markdown
Member

I'm okay with this at the MNE-Python end, but it does seem like a workaround... is there an upstream issue? Would be good to let them know this is an issue if they don't

In the meantime CIs have failed due to style (line too long), can you fix it?

Updated comment for clarity regarding inline backend behavior.
@mh105

mh105 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@larsoner I actually think this is an appropriate MNE-Python fix:

matplotlib "inline" backend is meant to be non-interactive similar to "agg", but that just means we can't manage the figure handle after its creation. plt.show() is a pyplot-level operation that displays all figures however the backend created them would display them.

I think the main issue here is that we always call fig.show(**kwargs) whenever the backend is not "agg" and the fig handle is not None in

(fig or plt).show(**kwargs)

But backend != "agg" doesn't cover these other backends that don't expose Figure-level manager but are nevertheless not headless rendering backends like Agg.

For this reason, I didn't want to add a condition to if show and backend != "agg":, because despite being non-interactive, plt.show(**kwargs) can still display non-interactive figures created with the "inline" backend. So far this is the only matplotlib-native displayable yet non-interactive backend that I can think of, hence the str search. If we find more in the future, perhaps we can handle this properly and modify the outer if loop all together (if show and backend != "agg":).

@mh105

mh105 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

I edited the comment line as well. The still failing CI seems to be out of my control...

@wmvanvliet

Copy link
Copy Markdown
Contributor

Could you register for an Circle-CI account so that the documentation CI can run?

@mh105
mh105 requested a review from agramfort as a code owner July 21, 2026 19:46
@larsoner
larsoner merged commit e39d640 into mne-tools:main Jul 21, 2026
29 checks passed
@larsoner

Copy link
Copy Markdown
Member

Thanks @mh105 !

@mh105
mh105 deleted the agent/upstream-inline-plt-show branch July 21, 2026 22:47
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.

3 participants