Tutorial clarification

I was reading the introductory Overview of MEG/EEG analysis with MNE-Python — MNE 1.11.0 documentation
tutorial.

But seems like this part is a bit quirky:

raw.compute_psd(fmax=50).plot(picks="data", exclude="bads", amplitude=False)
raw.plot(duration=5, n_channels=30)

I have to add block=True in order to view the plot on raw.plot otherwise it’ll close as soon as it opens up.
but ica.plot_properties(raw, picks=ica.exclude) doesn’t require that? Why? Is this a system design choice?

Plotting tools with a block argument tend to be those which open browsing figures (those that you scroll through), e.g., Epochs.plot, ICA.plot_sources.

In contrast, those that produce more ‘static’ figures don’t have a block argument, e.g., ICA.plot_properties, Spectrum.plot. At least for me (and also seems for you), running these in a file effectively acts as if block=True.

Why the more static plotting doesn’t have a block param and why the default seems to be opposite of that for browsing figures, I’m not sure. Perhaps @larsoner knows?

Does raw.plot() open the mne-qt-browser window, while ica.plot_properties() opens a matplotlib figure? Two different plotting engines could explain the difference.

I wondered this also, but I saw the same behaviour with raw.plot for both engines, and ultimately block=False by default regardless of engine choice.

Hmm this part is not good. If you do fig = raw.plot(…) does it stay up? The intended behavior is that it shows up but does not block execution.

If adding fig = … does fix it, it suggests it’s due to garbage collection – no ref to the figure is maintained so it gets GC’ed and closed. Plotting libraries usually take care of this by keeping a ref to all figures they’ve created in their own _ALL_PLOTTERS for example. We should probably implement this at the mne-qt-browser end if needed

Does adding plt.show() at the end not work?

If you do fig = raw.plot(…) does it stay up?

With mne-qt-browser engine, this doesn’t change the behaviour.


Does adding plt.show() at the end not work?

Yes, for the matplotlib engine. I guess you could achieve similar for mne-qt-browser with

app = QApplication.instance()
if app is not None:
    app.exec()

but it is more cumbersome.