You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ICA plot_components opens figure one by one (and might hang depending on the console) #11693
A video will be clearer. Same behavior in a regular python console and in an IPython console.
Screencast.from.05-12-2023.04.45.47.PM.webm
The figure are shown one by one after you close the old one. At least in a python or IPython console, it works. In spyder, it hangs the console after you close the first figure 😞
Tested both in a working environment and in a fresh environment with only pip install ipython mne installed (MNE 1.4).
the plots are not created within a plt.ion() context so they're blocking execution. A solution would be to generate (but not show) the figures in the for-loop over subsets of components, then show all of them at the end after the for-loop completes. Getting this stuff to work right in all contexts (notebook, ipython, spyder, pycharm) is tricky; don't hesitate to ask for help if you get stuck.
I have to say, this blocking/event-loop/backend aspect of matplotlib always eluded me. Couple of additional points:
This issue did not appear because of a change we made. Testing the same code snippet in python/IPython/Spyder with MNE 1.2 results in the same behavior while it was correctly displaying all figures a couple of months ago. I tried rolling back some dependencies, including matplotlib, without luck. Not sure which one is responsible.
One solution is to provide the argument block=False here:
After this change, it does correctly open all figures BUT:
from a regular python interpreter the call becomes non-blocking, thus the code snippet above by itself would run and end immediately. Maybe that's how it should be?
from an IPython console or from a regular python interpreter (blocked with an input() at the end), opening the properties plot by clicking on the topographies works but with the lovely QCoreApplication::exec: The event loop is already running. This warning is not present in Spyder.
show all of them at the end after the for-loop completes
I don't see an easy way to do it without adding an argument to flag if we are in a single execution (picks is not None) or in a recursive execution (initial call with picks=None) and I don't like this solution for a public function.
EDIT: I will rewrite this afternoon the function structure to remove the recursion, see if that helps.
Matplotlib backend used for testing: QtAgg with PyQt5.
More discoveries! In #11696 I removed the recursion in plot_ica_components and now gather all figures and show only once at the end. I don't see a downside in this approach, and it solves part of the issue. All the figures open at once.
# but wrapping it in ion() context makes it go away (can't actually use
# `with plt.ion()` as context manager, though, for compat reasons).
# Moving this bit to a separate function in ../../fixes.py doesn't work.
plt.ioff()
What is the purpose of those lines? If we remove them, everything works fine in python, ipython, spyder and jupyter (still needs to be tested in VSCode, PyCharm).
Activity
drammock commentedon May 12, 2023
the plots are not created within a
plt.ion()context so they're blocking execution. A solution would be to generate (but not show) the figures in the for-loop over subsets of components, then show all of them at the end after the for-loop completes. Getting this stuff to work right in all contexts (notebook, ipython, spyder, pycharm) is tricky; don't hesitate to ask for help if you get stuck.mscheltienne commentedon May 15, 2023
I have to say, this blocking/event-loop/backend aspect of
matplotlibalways eluded me. Couple of additional points:matplotlib, without luck. Not sure which one is responsible.block=Falsehere:mne-python/mne/viz/topomap.py
Line 1742 in 1e6aa7d
After this change, it does correctly open all figures BUT:
input()at the end), opening the properties plot by clicking on the topographies works but with the lovelyQCoreApplication::exec: The event loop is already running. This warning is not present in Spyder.And for your proposition @drammock
I don't see an easy way to do it without adding an argument to flag if we are in a single execution (
picksis not None) or in a recursive execution (initial call withpicks=None) and I don't like this solution for a public function.EDIT: I will rewrite this afternoon the function structure to remove the recursion, see if that helps.
Matplotlib backend used for testing:
QtAggwithPyQt5.mscheltienne commentedon May 15, 2023
More discoveries! In #11696 I removed the recursion in
plot_ica_componentsand now gather all figures and show only once at the end. I don't see a downside in this approach, and it solves part of the issue. All the figures open at once.But:
Speedy screencast to demonstrate (too bad it doesn't capture the mouse..)
Screencast.from.05-15-2023.02.46.05.PM.webm
And now the discovery part. It works on user-provided axes!
This works in all of those 4 tests and does not hang the interpreter in Spyder and Jupyter. Something is not behaving around here..
mne-python/mne/viz/utils.py
Lines 470 to 527 in 1e6aa7d
MNEFigurepart since bypassing_figurealso works.mscheltienne commentedon May 15, 2023
mne-python/mne/viz/_mpl_figure.py
Lines 78 to 85 in 1e6aa7d
What is the purpose of those lines? If we remove them, everything works fine in python, ipython, spyder and jupyter (still needs to be tested in VSCode, PyCharm).