Is it possible to plot the spectrogram of overnight sleep EEG data in mne? I don't want to create epochs but, have the spectrogram of continuous 8-9 hours. The examples I see in e.g. EEGlab (Matlab) have perfect color distinction which makes the outcome very readable. I would be grateful if you help me produce something similar but in mne.
Yes it is possible and quite easy!
Raphael Vallat's package yasa
has a function for doing exactly this for a single EEG channel from long-duration sleep data:
https://raphaelvallat.com/yasa/build/html/generated/yasa.plot_spectrogram.html
The function uses multitapers for estimating Wigner spectra, implemented in the package lspopt
, and is quite fast. While you could use this directly, yasa
takes care of a lot of moving parts and provides a more convenient interface.
The function accepts a 1D NumPy array, so you'll need to get the data for a single channel from the mne.Raw
object. For instance, if your EEG data is stored in the variable raw
, you can extract the data as a 2D NumPy array using raw.get_data()
and then select the desired row (channel). There are plenty of ways of selecting data, tabulated nicely in the documentation:
https://mne.tools/dev/auto_tutorials/raw/10_raw_overview.html#summary-of-ways-to-extract-data-from-raw-objects