"""Plot a simple EEG signal trace. For the EGOW project, week1. by Elliott Forney idfah@cs.colostate.edu Colorado State University 2013.04.04 """ import matplotlib.pyplot as plt import numpy as np import json # load from json dataHandle = open('s20-gammasys-gifford-unimpaired.json', 'r') data = json.load(dataHandle) dataHandle.close() # pull out first session data = data[0] # get sample rate sampRate = data['sample rate'] # get channel info chans = data['channels'] nchan = len(chans) # eeg signals from first trial eeg = np.array(data['eeg']['trial 1']).T # get first 5s, ommit trigger channel ns = 5.0 # seconds down eeg to start plot shift = 5.0 eeg = eeg[(shift*sampRate):((shift+ns)*sampRate),:nchan] # demean eeg -= np.mean(eeg, axis=0) # set up time and separator to add space between channels time = np.linspace(0.0,ns,sampRate*ns).repeat(nchan).reshape(eeg.shape) sep = np.max(np.abs(eeg))*np.arange(nchan-1,-1,-1) # plot it! fig = plt.figure(figsize=(12,6)) ax = fig.add_subplot(1,1,1) ax.plot(time, eeg+sep) ax.set_yticks(sep) ax.set_yticklabels(chans) ax.axis('tight') plt.show()