fishbacp
fishbacp

Reputation: 1263

Unable to scroll through raw data plot in MNE

I'm using the mne toolbox to analyze eeg data on my Mac (Catalina 10.15.4) and am having trouble creating a raw data plot that is interactive. Here's my code for loading the EEG file and plotting:

import mne as mn
raw = mn.io.read_raw_edf('/Users/fishbacp/Desktop/chb01_03.edf', preload=True)
raw.plot()

The resulting plot is not interactive insofar as I can't scroll through the data, and, in fact, the Help button on the bottom of the figure window is inactive.

In a Jupyter notebook environment I was able to solve the problem by inserting

%matplotlib qt

immediately before raw.plot(). However, now I'm working in IDLE (Python 3.7) and the same insertion only produces a syntax error.

Upvotes: 0

Views: 2280

Answers (3)

Ed9012
Ed9012

Reputation: 103

I encountered the same issues and the following worked for me:

import matplotlib
import PyQt5
import mne

raw_path = sample_data_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'
raw = mne.io.read_raw(raw_path)

plt.switch_backend('QtAgg')

raw.plot()
plt.pause(0.0001) 
%matplotlib

Upvotes: 0

JORDAN
JORDAN

Reputation: 9

You need to choose a backend before plotting the graph. There are two kinds of engines. One type of engine is interactive, the others are not.

import matplotlib
import pathlib
import mne

matplotlib.use('Qt5Agg')

raw_path = sample_data_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'
raw = mne.io.read_raw(raw_path)

raw.plot()

https://matplotlib.org/stable/api/matplotlib_configuration_api.html?highlight=use#matplotlib.use

Check this out.

Upvotes: 0

fishbacp
fishbacp

Reputation: 1263

Here is a solution that worked for me:

import mne as mn
import matplotlib.pyplot as plt

#plt.switch_backend('TkAgg') You can use this backend if needed
plt.ion() #Makes plot interactive

raw = mn.io.read_raw_edf('/Users/fishbacp/Desktop/chb01_03.edf', preload=True)

raw.plot()

Upvotes: 1

Related Questions