3D figure closed immediately after plotting

Hi, I got a problem when running the mne tutorial codes and the figure closed immediately after plotting. I tried both pyvista and mayavi and got the same result.
It looks like a similar problem like this and this.
And I try ticking ā€œRun with Python Consoleā€ box accroding to here, but it doesnā€™t work.
My environment is conda mne.
Please tell me how to solve this, thanks.

I believe @cbrnr is using PyCharm and might be able to help.

In the meantime, could you please share the output of

import mne
mne.sys_info()

Thanks

Thanks for your reply. There are my system info:

Platform:      Windows-10-10.0.19042-SP0
Python:        3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:37:25) [MSC v.1916 64 bit (AMD64)]
Executable:    D:\Applications\Miniconda3\envs\mne\python.exe
CPU:           Intel64 Family 6 Model 140 Stepping 1, GenuineIntel: 8 cores
Memory:        15.8 GB
mne:           0.23.0
numpy:         1.21.1 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy:         1.7.0
matplotlib:    3.4.2 {backend=module://backend_interagg}
sklearn:       0.24.2
numba:         0.53.1
nibabel:       3.2.1
nilearn:       0.8.0
dipy:          1.4.1
cupy:          Not found
pandas:        1.3.0
mayavi:        4.7.2
pyvista:       0.31.3 {pyvistaqt=0.5.0, OpenGL 4.5.0 - Build 27.20.100.9415 via Intel(R) Iris(R) Xe Graphics}
vtk:           9.0.1
PyQt5:         5.12.3

I just tried running a simpler tutorial (right-click the file tab and click ā€˜Run 20_event_arraysā€™), and without changing any setting the plot opens. Can you try if this tutorial works for you?

For some reason I cannot run 35_eeg_no_mri.py because:

RuntimeError: Could not load any valid 3D backend: pyvista, mayavi, notebook

I do have pyvista and PyQt5 installed though. @richard any idea?

You sure youā€™re using the correct environment to run this?

Iā€™m using my own venv with those packages installed.

I didnā€™t download the tutorials data so I run the method mne.viz.plot_events on my own data and it works well. The events plot on the screen and doesnā€™t close immediately.

I had the same problem once, after I used the conda mne envs, this error disappeared.

OK, I was missing pyvistaqt ā€“ maybe this could be mentioned in the RuntimeError (since I did have pyvista installed)?

Regarding the initial question, all figures open but are closed when the script finishes. However, when I set ā€œRun with Python consoleā€ in the run configuration, all figures remain open.

1 Like

No problem here whatsoever on macOS with the conda-forge-based environment and mne-python:main.

When I run viz.plot_events, I could get an expected resultā€”ā€”the figure ploted on the window and wonā€™t closed automatically untill the close button was clicked. But when running viz.plot_alignment, the figure just flash across. I wonder how to let the figure stay?
Setting ā€œRun with Python consoleā€ seems donā€™t work for meā€¦

What happens if you simply copy-and-paste your code into an interactive Python window?

Are you sure that you have set it in the correct Run Configuration? Hereā€™s what it looks like for me:

2 Likes

oh, I checked and it works! :rofl: Thank you ~

1 Like

Would be good, care to open an issue?

1 Like

@richard Better error message for 3D plots when pyvistaqt is missing Ā· Issue #9606 Ā· mne-tools/mne-python Ā· GitHub

1 Like