def plot_filtered_performance_calendar(subj, df, num_days=7, **kwargs): ''' plots a calendar view of the performance for a subject on the past num_days. ''' return plot_performance_calendar( subj, utils.filter_normal_trials(utils.filter_recent_days(df, num_days)), **kwargs)
def plot_filtered_accperstim(title, df, num_days=7, **kwargs): ''' plots accuracy per stim for a subject on the past num_days. ''' plot_accperstim( title, utils.filter_normal_trials(utils.filter_recent_days(df, num_days)), **kwargs)
def plot_accuracy_bias(subj, df, x_axis='time', smoothing='exponential', trial_lim=None, day_lim=12, plt_correct_smoothed=True, plt_correct_shade=True, plt_correct_line=True, plt_L_response_smoothed=False, plt_L_response_shade=False, plt_L_response_line=False, plt_R_response_smoothed=False, plt_R_response_shade=False, plt_R_response_line=False, plt_ci=False, block_size=100, return_fig=False): ''' plots the accuracy or bias of the subject. Parameters: ----------- subj : str the subject df : pandas DataFrame data frame of behavior data x_axis : str whether to plot 'time' or 'trial_num' along the x axis smoothing : str whether to smooth using 'exponential', 'rolling' average, 'gaussian' filter' trial_lim : None or int max number of most recent trials to include day_lim : None or non-negative int max number of days of trials to include. Zero means just today. plt_{correct, L_response, R_response}_smoothed : boolean whether to plot a smoothed line for the value plt_{correct, L_response, R_response}_shade : boolean whether to plot a red shaded region filling in the line of actual responses plt_{correct, L_response, R_response}_line : boolean whether to plot a red line of the actual responses ''' fig = plt.figure(figsize=(16, 2)) if trial_lim is not None: df = df[-trial_lim:] if day_lim is not None: df = utils.filter_recent_days(df, day_lim) df = utils.filter_normal_trials(df) if x_axis == 'time': x = df.index._mpl_repr() use_index = True elif x_axis == 'trial_num': x = np.arange(len(df)) use_index = False else: raise Exception('invalid value for x_axis') datas = (df['correct'], df['response'] == 'L', df['response'] == 'R') plot_smoothed_mask = (plt_correct_smoothed, plt_L_response_smoothed, plt_R_response_smoothed) plot_shaded_mask = (plt_correct_shade, plt_L_response_shade, plt_R_response_shade) plot_line_mask = (plt_correct_line, plt_L_response_line, plt_R_response_line) for data, smoothed, shaded, line in zip(datas, plot_smoothed_mask, plot_shaded_mask, plot_line_mask): if shaded: plt.fill_between(x, .5, data.values.astype(bool), color='r', alpha=.25) if line: #return data g = plt.plot(data.values.astype(bool), color='r', marker='o', linewidth=.5) if smoothed: if smoothing == 'exponential': data.ewm(halflife=20).mean().plot(use_index=use_index) elif smoothing == 'gaussian': plt.plot( x, sp.ndimage.filters.gaussian_filter( data.values.astype('float32'), 3, order=0)) elif smoothing == 'rolling': try: data.rolling(window=block_size, center=True).mean().plot(use_index=use_index) except TypeError as e: print(e) continue else: raise Exception('invalid value for smoothing') if plt_ci and smoothing == 'rolling': ci = utils.binomial_ci(0.5 * block_size, block_size) plt.axhspan(ci[0], ci[1], color='grey', alpha=0.5) plt.axhline(y=.5, c='black', linestyle='dotted') plt.title('Today\'s Performance: ' + subj) plt.xlabel(x_axis) if return_fig: return fig