ica.plot_components() causes program to hang

Hello everyone,

Iā€™m having trouble with MNEā€™s ica.plot_components() function. When I call this function, my program seems to completely hang. Thereā€™s no error message, but thereā€™s also no expected output.

Hereā€™s the code Iā€™m trying to run:

ica = ICA(n_components=40, random_state=97)
ica.fit(raw_filt)
ica.plot_components()

I have tried the following solutions, but the problem persists:

  1. Reducing the number of ICA components
  2. Disabling interactive plotting
  3. Updating MNE and relevant packages to the latest versions

Here are the details of my environment:

  • Operating System: Windows 10 and win11 (I tried on different devices)
  • Python Version: (3.9 ; 3.8)
  • MNE Version: (1.2 ; 1.3)
  • NumPy Version: (1.24.3)
  • SciPy Version: (1.10.1)
  • Matplotlib Version: (-base=3.7.1; -inline=0.1.6)

The data Iā€™m working with is EEG data, and its size is 500mb. Iā€™m wondering if anyone else has encountered a similar problem, or if anyone knows how to solve this issue. Any help would be greatly appreciated.

Thank you for your time and help!

Can you save and share your ICA solution (ica.save())?

sorry, it seems the forums donā€™t permit this kind of file to be uploaded.

Perhaps you can put it on Dropbox/Google Drive/OneDrive/etc. and share a link?

[image]
ę–‡ä»¶å¤§å°: 54.4 KB 分äŗ«å†…容: ica
é“¾ęŽ„åœ°å€:https://pan.bnu.edu.cn/l/X1u1Ar

Could you try this one?

Works fine on my computer:

import mne

ica = mne.preprocessing.read_ica("ica")
ica.plot_components()

Maybe thereā€™s something wrong with your interactive plotting settings? Do you run the code with python, ipython, within a Jupyter notebook, ā€¦?

yes, I ran this on jupyter in pycharm!

In contrast to others, I do not recommend to use Jupyter notebooks (you are not the first person to encounter problems with visualizations). In my experience, a plain interactive interpreter session (which includes IPython), works much better for (interactive) data analysis. PyCharm has a very nice integrated Python terminal, please try if this solves your issue.

Please do try out @cbrnr 's suggestion, but just FYI, when I am using MNE visualization functions within a Jupyter notebook, I run %matplotlib qt in a cell before doing any plotting

I think mne.preprocessing.plot_components uses a matplotlib backend so this might solve your issue.

EDIT: FYI I think %matplotlib qt requires that you have the pyqt5 python package installed

thanks for your advice Scott. I have tried matplotlib qt/ inline. It works well while I doing other plot. Only the plot_component encountered the problem.

Can you try ica.plot_components(show=True)?