-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Description of the problem
When trying to visualize mne data in a jupyter notebook, I get the following error:
'NoneType' object has no attribute '_get_renderer'
Steps to reproduce
So this is a strange one, everything was working perfectly and then I tried to get pyqt to work and now I can't have the normal matplotlib inline experience in jupyter notebooks.
The code runs fine and the plots show normally in a python script, but crashes in a jupyter notebook.
I was unable to reproduce it on the sample datasets, I'm providing a snippet of my dataset.
In a notebook, load the data and try to visualize evoked data.
import mne
raw = mne.io.read_raw_fif("demo-data.fif", preload=True)
events, event_dict = mne.events_from_annotations(raw)
epochs = mne.Epochs(
raw,
events,
event_id=event_dict,
tmin=-.5,
tmax=1,
)
epochs[["Test Trial"]].average().plot()
Link to data
https://drive.google.com/file/d/1hAVBZaxg1ZVorf5djqbDB8mdhAtdkf5v/view?usp=sharing
Expected results
I should see the plot
Actual results
I get the following stack trace:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File ~\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\lib\site-packages\IPython\core\formatters.py:340, in BaseFormatter.__call__(self, obj)
338 pass
339 else:
--> 340 return printer(obj)
341 # Finally look for special method names
342 method = get_real_method(obj, self.print_method)
File ~\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\lib\site-packages\IPython\core\pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 from matplotlib.backend_bases import FigureCanvasBase
150 FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
153 data = bytes_io.getvalue()
154 if fmt == 'svg':
File ~\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\lib\site-packages\matplotlib\backend_bases.py:2353, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2350 bbox_inches = bbox_inches.padded(pad_inches)
2352 # call adjust_bbox to save only the given area
-> 2353 restore_bbox = _tight_bbox.adjust_bbox(
2354 self.figure, bbox_inches, self.figure.canvas.fixed_dpi)
2356 _bbox_inches_restore = (bbox_inches, restore_bbox)
2357 else:
File ~\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\lib\site-packages\matplotlib\_tight_bbox.py:28, in adjust_bbox(fig, bbox_inches, fixed_dpi)
26 locator = ax.get_axes_locator()
27 if locator is not None:
---> 28 ax.apply_aspect(locator(ax, None))
29 locator_list.append(locator)
30 current_pos = ax.get_position(original=False).frozen()
File ~\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\lib\site-packages\mpl_toolkits\axes_grid1\inset_locator.py:73, in AnchoredLocatorBase.__call__(self, ax, renderer)
71 def __call__(self, ax, renderer):
72 self.axes = ax
---> 73 bbox = self.get_window_extent(renderer)
74 px, py = self.get_offset(bbox.width, bbox.height, 0, 0, renderer)
75 bbox_canvas = Bbox.from_bounds(px, py, bbox.width, bbox.height)
File ~\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\lib\site-packages\matplotlib\offsetbox.py:399, in OffsetBox.get_window_extent(self, renderer)
396 def get_window_extent(self, renderer=None):
397 # docstring inherited
398 if renderer is None:
--> 399 renderer = self.figure._get_renderer()
400 bbox = self.get_bbox(renderer)
401 try: # Some subclasses redefine get_offset to take no args.
AttributeError: 'NoneType' object has no attribute '_get_renderer'
Additional information
I've tried uninstalling and reinstalling all packages, adding and removing all visualization packages as well. I can get the plots to show on sample data in a notebook and even on my data but not in notebooks.
I've been able to reproduce it in a fresh project and in a fresh env, with only mne installed.
mne.sys_info()
Platform Windows-10-10.0.19044-SP0
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]
Executable C:\Users\\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject-lFcWie39-py3.10\Scripts\python.exe
CPU Intel64 Family 6 Model 140 Stepping 1, GenuineIntel (8 cores)
Memory 31.7 GB
Core
├☑ mne 1.4.2
├☑ numpy 1.25.1 (unknown linalg bindings (threadpoolctl module not found: No module named 'threadpoolctl'))
├☑ scipy 1.11.1
├☑ matplotlib 3.7.2 (backend=module://matplotlib_inline.backend_inline)
├☑ pooch 1.7.0
└☑ jinja2 3.1.2
Numerical (optional)
└☐ unavailable sklearn, numba, nibabel, nilearn, dipy, openmeeg, cupy, pandas
Visualization (optional)
└☐ unavailable pyvista, pyvistaqt, ipyvtklink, vtk, qtpy, ipympl, pyqtgraph, mne-qt-browser
Ecosystem (optional)
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline
poetry show
(pythonproject-py3.10) C:\Users\\PycharmProjects\pythonProject>poetry show
certifi 2023.5.7 Python package for providing Mozilla's CA Bundle.
charset-normalizer 3.2.0 The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
colorama 0.4.6 Cross-platform colored terminal text.
contourpy 1.1.0 Python library for calculating contours of 2D quadrilateral grids
cycler 0.11.0 Composable style cycles
decorator 5.1.1 Decorators for Humans
fonttools 4.41.0 Tools to manipulate font files
idna 3.4 Internationalized Domain Names in Applications (IDNA)
jinja2 3.1.2 A very fast and expressive template engine.
kiwisolver 1.4.4 A fast implementation of the Cassowary constraint solver
markupsafe 2.1.3 Safely add untrusted strings to HTML/XML markup.
matplotlib 3.7.2 Python plotting package
mne 1.4.2 MNE-Python project for MEG and EEG data analysis.
numpy 1.25.1 Fundamental package for array computing in Python
packaging 23.1 Core utilities for Python packages
pillow 10.0.0 Python Imaging Library (Fork)
platformdirs 3.8.1 A small Python package for determining appropriate platform-specific dirs, e.g. a "user data dir".
pooch 1.7.0 "Pooch manages your Python library's sample data files: it automatically downloads and stores them in a local directory, with support for versioning and corruption checks."
pyparsing 3.0.9 pyparsing module - Classes and methods to define and execute parsing grammars
python-dateutil 2.8.2 Extensions to the standard Python datetime module
requests 2.31.0 Python HTTP for Humans.
scipy 1.9.3 Fundamental algorithms for scientific computing in Python
six 1.16.0 Python 2 and 3 compatibility utilities
tqdm 4.65.0 Fast, Extensible Progress Meter
urllib3 2.0.3 HTTP library with thread-safe connection pooling, file post, and more.
Thanks in advance !