Skip to content

Matplotlib plot in jupyterlab using Qt hangs except if an inline plot was produced before  #11510

@Brandsd0

Description

@Brandsd0

Description of the problem

Plotting the ICA components in jupyter-lab, I use the interactive Qt backend with %matplotlib qt to label components.
If an inline figure is plotted prior to this, then everything works.
If not, closing the window does hang the interpreter and I have to send a keyboard interrupt to keep going. The ICA components labeled before the interrupt arrive in ica.exclude safely.

Steps to reproduce

With inline plot before, working and correct behavior:

Cell 1:


from mne.datasets import sample
from mne.io import read_raw_fif
from mne.preprocessing import ICA


directory = sample.data_path() / "MEG" / "sample"
raw = read_raw_fif(directory / "sample_audvis_raw.fif", preload=False)
raw.crop(0, 20)
raw.pick_types(eeg=True)
raw.load_data()
raw.filter(1., 100.)
ica = ICA(n_components=10, method="picard")
ica.fit(raw)

Cell 2:

ica.plot_components()

This last command plots the figure inline.
Edit 'Cell 2' and rerun:

%matplotlib qt
ica.plot_components()

Closing the figure correctly gives me back control of the interpreter.


Bug behavior:

Cell 1 is similar as before.
Cell 2 directly:

%matplotlib qt
ica.plot_components()

Without any prior matplotlib plots. The interpreter now hangs.

Additional information

Platform:         macOS-13.0.1-x86_64-i386-64bit
Python:           3.10.10 (main, Feb 13 2023, 03:30:25) [Clang 14.0.0 (clang-1400.0.29.202)]
Executable:       /Users/sierrabrandts/pyvenv/eeg-flow/bin/python
CPU:              i386: 8 cores
Memory:           8.0 GB

mne:              1.4.dev0
numpy:            1.23.5 {OpenBLAS 0.3.20 with 4 threads}
scipy:            1.10.0
matplotlib:       3.7.0 {backend=MacOSX}

sklearn:          1.2.1
numba:            0.56.4
nibabel:          5.0.1
nilearn:          0.10.0
dipy:             1.6.0
openmeeg:         Not found
cupy:             Not found
pandas:           1.5.3
pyvista:          0.38.2 {OpenGL 4.1 INTEL-20.2.44 via Intel(R) Iris(TM) Plus Graphics OpenGL Engine}
pyvistaqt:        0.9.1
ipyvtklink:       0.2.3
vtk:              9.2.6
qtpy:             2.3.0 {PyQt5=5.15.2}
ipympl:           0.9.2
pyqtgraph:        0.13.1
pooch:            v1.6.0

mne_bids:         0.13.dev0
mne_nirs:         Not found
mne_features:     Not found
mne_qt_browser:   0.5.dev0
mne_connectivity: Not found
mne_icalabel:     0.5.dev0

pinging @mscheltienne who investigated quickly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions