def plot_targ_perc_correct(hdf, plot_seq=True, nested_te_list=None, indicator_labels=None): cnt = -1 flat_te_list = list(np.hstack((nested_te_list))) if nested_te_list is not None: cm = [] for te_day in nested_te_list: cnt += 1 for d in te_day: cm.append(cnt) flat_te_list = list(np.hstack((nested_te_list))) else: flat_te_list = np.unique(hdf.root.meta_metrics[:]['task_entry']) print cm te_dict = {} for row in hdf.root.meta_metrics[:]: for tg in range(8): if (row['task_entry'], tg) in te_dict.keys() and row['task_entry'] in flat_te_list: te_dict[row['task_entry'], tg].append(row['targ_percent_success'][tg]) else: te_dict[row['task_entry'], tg] = [row['targ_percent_success'][tg]] input_dict = dict() for k in te_dict.keys(): #Find entry in other table with same number: ix = np.nonzero(hdf.root.trial_metrics[:]['task_entry']==k[0])[0] input_type = hdf.root.trial_metrics[ix[0]]['input_type'] input_dict[k] = input_type f, ax = plt.subplots(nrows=3, ncols=3) off = 0 for i, k in enumerate(flat_te_list): # if input_dict[k] == 'all': # color='k' # elif input_dict[k] == 'shared_sc': # color = 'r' color = cmap[cm[i]] for tg in range(8): ax_ix = bha.targ_ix_to_3x3_subplot(tg) axi = ax[ax_ix[0], ax_ix[1]] if (k, tg) in te_dict.keys(): axi.plot((np.arange(len(te_dict[k, tg]))*2.5)+off, te_dict[k, tg], '-', color=color) else: print ' no: ', k, tg try: off += len(te_dict[k, tg])*2.5 except: print 'no need to increment off' #ax.set_ylabel('Perc Success Rate') #ax.set_xlabel('Time (min) over Session') for axi in ax: for axii in axi: axii.set_ylim([0, 1.]) plt.tight_layout()
def plot_by_targ_and_input_type(metric_wanted, met_hdf, ylabel=None, ylim=None, stats=True, input_type=None, collapse_targ=False, subset_tes=None, subset_cond=None): #Init figure if collapse_targ: f, ax = plt.subplots() else: f, ax = plt.subplots(nrows=3, ncols=3) if subset_cond is None: add_subset = '' else: add_subset = ' & '+subset_cond targs = np.unique(met_hdf.root.trial_metrics[:]['target_index']) if subset_tes is None: subset_tes = np.unique(met_hdf.root.trial_metrics[:]['task_entry']) ix = np.arange(len(met_hdf.root.trial_metrics)) else: ix = np.array([i for i, j in enumerate(met_hdf.root.trial_metrics[:]['task_entry']) if j in subset_tes]) if input_type is None: inputs = np.unique(met_hdf.root.trial_metrics[ix]['input_type']) else: tmp_inp = np.array([input_type[te] for te in subset_tes]) inputs = np.unique(tmp_inp) tr_table = met_hdf.root.trial_metrics master_times = [] #Iterate through target num (target_index in hdf file) for it in targs: #Init empty arryays and names: times = [] nms = [] #Iterate through 'fa_inputs': for inp in inputs: #Set pytable query if input_type is None: cond = '(target_index == it) & (input_type == inp)'+add_subset else: inp_times = [] #Get TEs w/ correct input: te_arr = np.array([te for te in input_type.keys() if input_type[te] == inp]) cond = [] for te in te_arr: cond.append('(target_index == it) & (task_entry == te)'+add_subset) #Add desired metric of trials that are of correct input type and target index if type(cond) == str: times.append([x[metric_wanted] for x in tr_table.where(cond)]) else: for c in cond: inp_times.extend([x[metric_wanted] for x in tr_table.where(c)]) times.append(inp_times) nms.append(inp) if collapse_targ: if len(master_times) == 0: master_times = times else: for i, t in enumerate(times): master_times[i].extend(times[i]) else: #Map target index to correct subplot location axi = ax[bha.targ_ix_to_3x3_subplot(it)] #Boxplot z = seaborn.boxplot(times, names=nms, ax=axi, fliersize=0, whis=0.) plt.setp(z.get_xticklabels(), rotation=45) #Plot stats: if stats: print 'stats for targ ix: ', it, len(times), len(nms) axi, dy = add_stats(axi, times, nms, ylim) if ylim is not None: axi.set_ylim([ylim[0], ylim[1]+6*dy]) if collapse_targ: z = seaborn.boxplot(master_times, names=nms, ax=ax, fliersize=0, whis=0.) plt.setp(z.get_xticklabels(), rotation=45) if stats: print 'stats for master' axi, dy = add_stats(ax, master_times, nms, ylim) if ylim is not None: ax.set_ylim([ylim[0], ylim[1]+6*dy]) ax.set_title(metric_wanted) else: ax[0, 1].set_title(metric_wanted) if ylabel is not None: for i in range(3): ax[i, 0].set_ylabel(ylabel) #Magic plt.tight_layout()