I’m relatively new to Python and completely new to EEG analysis so I’m working through the tutorial (specifically the Overview of MEG/EEG analysis). I’ve encountered some difficulty early in the process and I’m not sure how to fix it. I’ve searched the forum and found two posts that seemed to have the same error message (here and here) and both appear to have been solved up updating matplotlib to 3.8.0 which I have done. However, i’m still getting the same error.
I’ve just created a fresh environment with MNE 1.5.1 and I don’t replicate the error (though I’m on linux, not windows).
The traceback goes through ipython.pylabtools.print_figure and then a bunch of the matplotlib namespace, which makes me think either this is a specialized console or a notebook… can you say more about your execution environment?
(that said, it also works for me in an .ipynb cell run thorough VSCode or through jupyter notebook)
I appreciate the reply. That’s starting to get into areas of python that I don’t quite understand. I’ll do my best to describe what I did.
This is a fresh install of Anaconda using all the default settings. I launched Spyder 5.4.3 from the Anaconda Navigator. I installed MNE via pip install mne. I also used pip install numpy and pip install matplotlib to ensure I had the most recent versions of those packages as well.
I’m not sure if there is other information you need, or if there’s output from another command that will be helpful, please let me know and I’ll be happy to provide that as well.
that already helps, knowing that you’re within Spyder, and how you installed MNE. If you can, I would strongly recommend using our standalone installers rather than using pip to install MNE into your base anaconda environment.
In fact, generally speaking it is discouraged to install anything into your base anaconda environment. If you can’t / don’t want to use our installers, then I would suggest instead the following:
I uninstalled anaconda/python and then downloaded and installed via the standalone installer. This appears to have fixed the issue… kind of.
When I run raw.compute_psd(fmax=50).plot(picks="data", exclude="bads"), a plot appears in the Plots tab of Spyder. This is new. However, I still get an Attribute Error
Effective window size : 13.639 (s)
Traceback (most recent call last):
File ~\AppData\Local\mne-python\1.5.1_0\Lib\site-packages\IPython\core\formatters.py:340 in __call__
return printer(obj)
File ~\AppData\Local\mne-python\1.5.1_0\Lib\site-packages\IPython\core\pylabtools.py:152 in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File ~\AppData\Local\mne-python\1.5.1_0\Lib\site-packages\matplotlib\backend_bases.py:2353 in print_figure
restore_bbox = _tight_bbox.adjust_bbox(
File ~\AppData\Local\mne-python\1.5.1_0\Lib\site-packages\matplotlib\_tight_bbox.py:28 in adjust_bbox
ax.apply_aspect(locator(ax, None))
File ~\AppData\Local\mne-python\1.5.1_0\Lib\site-packages\mpl_toolkits\axes_grid1\inset_locator.py:73 in __call__
bbox = self.get_window_extent(renderer)
File ~\AppData\Local\mne-python\1.5.1_0\Lib\site-packages\matplotlib\offsetbox.py:399 in get_window_extent
renderer = self.figure._get_renderer()
AttributeError: 'NoneType' object has no attribute '_get_renderer'
Is there something else I need to do?
Also, this doesn’t cause a pop out window with the graph, but raw.plot(duration=5, n_channels=30) has a pop out, but no longer appears in the Plots tab. Do you know if this is expected behavior?
raw.plot() is a highly interactive figure, and by default it uses pyqtgraph instead of matplotlib as its backend plotting library (there is an option to force it to use matplotlib if needed). That is almost surely the reason why the raw.plot() call creates a separate window, and the spectrum.plot() call gets captured by Spyder and put into the “plots” pane (i.e., Spyder only intercepts matplotlib plots, not pyqtgraph plots).
As far as I can tell, this problem is a bug with Spyder and not with MNE-Python. I think you can work around it by going into Spyder preferences: Preferences > IPython Console > Graphics (tab) and either choosing Backend=Automatic, or if that doesn’t work, unticking “activate support”. That should make it so that matplotlib plots also pop open new windows.
One more question though: are you launching the version of spyder that was installed as part of the MNE standalone installer? Or did you separately install Spyder some other way? If you are using a separately-installed spyder there’s a chance that switching to the MNE-installed spyder might fix it.
I’m launching it using Spyder (MNE) when I search for apps so I assume I’m launching the version of Spyder that was included with the standalone installer.
I ran mne.sys_info() and noticed that it was using matplotlib 3.7.2 instead of 3.7.3 or 3.8, but since everything is kinda working, I’m afraid to even try and update it.
Sounds like you’re using the correct spyder version. I wouldn’t worry about updating matplotlib unless you know that you need features that were introduced in 3.8 (MNE plots don’t).
Was the Spyder preferences workaround successful, or do you still see the error? Are the plots popping up a new window now?
Both graphs are being plotted in a new window, which is fine. That was never really an issue for me; I was just wondering why it behaved that way.
That being said, I changed the python settings. I’m still getting the AttributeError: 'NoneType' object has no attribute '_get_renderer' error. But the plot is there, which I think is the point in the tutorial so I’m just going to shrug, say computers are stupid, and move on.