def plot_comparison(f1, f2, data, xs=[-0.5, 7], ys=[-400, 1000], s=0): '''Compare file 1 (red) with file 2 (blue), taking the mean and std of the signal''' d = handler.extract_data(f1) d2 = handler.extract_data(f2) # due to the 60Hz noise of the water heater, I have to filter it out with a notch filter temp = np.array([56.0,64.0])/(d['fs']/2.0) # 3 is the highest order I can go without it going crazy b,a = butter(3, temp[0], btype='bandstop') y = filtfilt(b,a,lowpass_filter((d['stim']*1e6, d['fs']))[0].T).T y2 = filtfilt(b,a,lowpass_filter((d2['stim']*1e6, d2['fs']))[0].T).T ystd = np.std(y, axis=1) ymean = average((y, d['fs']))[0][:,0] t = d['t']*1e3 y2std = np.std(y2, axis=1) y2mean = average((y2, d2['fs']))[0][:,0] t2 = d2['t']*1e3 plt.figure(figsize=(8,6)) plt.fill_between(t, (ymean-ystd), (ymean+ystd), alpha=0.5, facecolor=color_palette[0]) plt.plot(t, ymean, color=color_palette[0]) plt.fill_between(t2, y2mean - y2std, y2mean + y2std, alpha=0.5, facecolor=color_palette[5]) plt.plot(t2, y2mean, color=color_palette[5]) plt.xlim(xs) plt.ylim(ys) plt.ylabel('Voltage (µV)') plt.xlabel('Time (ms)') plt.title(descriptive_title(f1).replace('<br>', '\n')) plt.legend([str(handler.get_current(data,f1))+'µA', str(handler.get_current(data,f2))+'µA']) if s and type(s) == str: plt.savefig(s + '.pdf') elif s: plt.savefig(f1[:-4]+ f2[:-4]+'-comaparison.pdf')
def generate_tiled_plot(filelabel, tile=True, factor=50): plot_data = [] t = None func = compose(average, lowpass_filter) for i, (l, f) in enumerate(filelabel): offset = i * factor if tile else 0 data = handler.extract_data(f) if type(t) == type(None): t = data['t'] y, fs = func((data['stim'], data['fs'])) plot_data += [Scatter(x=t*1e3, y=y[:,0]*1e6 + offset, name=str(l), line=dict(width=2))] fig = {'data': plot_data} fig['layout'] = dict( title='Current-response comparison', xaxis=dict(title='Time (ms)'), yaxis=dict(title='Current increasing -->') ) return fig
def generate_tiled_plot(filelabel, tile=True, factor=50): plot_data = [] t = None func = compose(average, lowpass_filter) for i, (l, f) in enumerate(filelabel): offset = i * factor if tile else 0 data = handler.extract_data(f) if type(t) == type(None): t = data['t'] y, fs = func((data['stim'], data['fs'])) plot_data += [ Scatter(x=t * 1e3, y=y[:, 0] * 1e6 + offset, name=str(l), line=dict(width=2)) ] fig = {'data': plot_data} fig['layout'] = dict(title='Current-response comparison', xaxis=dict(title='Time (ms)'), yaxis=dict(title='Current increasing -->')) return fig