Saving EEG plot of rawarray not working

  • Not sure which version of MNE, but using Windows 10 and Jupyter Notebook

I can’t seem to save my figures of RawArray plots of EEG data.

raw_A_S1T1 = scipy.io.loadmat(path_A_S1T1)
raw_data_A_S1T1 = raw_A_S1T1['Data']
info = mne.create_info(ch_names = channel_names, sfreq = Fs, ch_types = ch_type)
raw_A_S1T1.plot(title='Raw data A_S1T1', n_channels=n_channels, scalings='auto', show=False)
plt.savefig('Raw_EEG_data_S1T1.png')

Without the “show = False”, this MNE figure pops up correctly.
However, I want it in a better format as this is going to be presented in my master’s thesis

The png figure is saved in folder, but when I open it it is just blank.
(This method, however, works for topomaps, maybe because they are shown directly in jupyter ide, and not via mne?)
Can anybody help me?

It’s going to be difficult to help you here. This is not what the data browser is designed to do. It’s an interactive browser, and based on the screenshot you provided, you are using the latest mne-qt-browser which provides a smoother experience. However, this browser is a Qt application, it’s not a matplotlib plot, thus plt.savefig will not work.

I think screenshots or a screen-capture might be your best bet.

EDIT: plt.savefig works for topomap because MNE returns a matplotlib Figure.

I see…
Do you know any way other way to plot the EEG data channel-wise, so that the figure is save-able?

if you want a raw browser plot that is suitable for inclusion in a paper, I suggest this:

with mne.viz.use_browser_backend('matplotlib'):
    fig = raw.plot()
    fig.savefig('filename.png')  # or PDF, JPEG, whatever matplotlib supports

consider the option show_scrollbars=False to make it look a little nicer.

2 Likes

Thank you! This I can work with!