def plot_weight_dist(weights, plt_num=[1, 1, 1]): """ plot a histogram of the learnt weight distribution """ ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) plt.hold(True) plt.hist(weights, 40) adjust_spines(ax, ['bottom', 'left']) plt.title('Weight Distribution')
def plot_preds_orient(weights, plt_num=[1, 1, 1]): orients = ['Mean Horiz', 'Mean Vert', 'Mean Diag', 'Mean Diag 2'] ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) x = 7 mid = x / 2 vals_hor = np.zeros([x, x]) vals_ver = np.zeros([x, x]) vals_diag = np.zeros([x, x]) delta = (mid / 2) vals_hor[mid, [mid - delta, mid + delta]] = 1 vals_ver[[mid - delta, mid + delta], mid] = 1 x, y = np.diag_indices_from(vals_diag) vals_diag[x[mid - delta], y[mid - delta]] = 1 vals_diag[x[mid + delta], y[mid + delta]] = 1 vals_diag2 = np.array(zip(*vals_diag[::-1])) # delta = mid - mid / 2 # vals_hor[mid, [mid - delta, mid + delta]] = 1 # vals_ver[:, mid] = 1 # np.fill_diagonal(vals_diag, 1) # np.fill_diagonal(vals_diag2, 1) # vals_diag2 = np.array(zip(*vals_diag2[::-1])) dat = (vals_hor * weights[0] + vals_ver * weights[1] + vals_diag * weights[2] + vals_diag2 * weights[3]) dat = reverse_fft(dat) ext = mid _ = plt.imshow(dat, cmap=colors.CoolWarm, interpolation='bilinear', extent=(-ext, ext, -ext, ext)) ylims = np.array([0, np.abs(dat).max()]) plt.clim(ylims) plt.colorbar() adjust_spines(ax, [])
def plot_mean_std(mn, std, title, plt_num=[1, 1, 1]): """plot the mean +/- std as timeline """ ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) plt.hold(True) plt.fill_between(range(len(std)), mn - std, mn + std, facecolor=clr2) plt.plot(range(len(std)), mn, color=clr1, label='Mean Center', linewidth=2) plt.legend(bbox_to_anchor=(0.55, 0.95, 0.4, 0.1), frameon=False, ncol=2) adjust_spines(ax, ['bottom', 'left']) plt.title(title)
def plot_summary(cmb_corrs, fig_path, extras=''): """ plot a summary showing the mean and std for all attempted combinations""" fig = plt.figure(figsize=(14, 12)) ax = plt.subplot(111) adjust_spines(ax, ['bottom', 'left']) colors = ['r', 'b', 'g', 'y', 'c', 'm'] _ = plt.subplot(111) xaxis = [] xvals = [] boxes = [] lbls = [] #targets.append('Overall') offset = -1 for i, k in enumerate(sorted(cmb_corrs.keys())): offset += 2 min_x = offset for j, cmb in enumerate(sorted(cmb_corrs[k].keys())): xaxis.append(cmb) xvals.append(offset) dat = cmb_corrs[k][cmb] if len(dat) == 0: continue col = colors[i] # do_box_plot(np.array(dat), np.array([i + offset]), # col, widths=[0.2]) do_spot_scatter_plot(np.array(dat), offset, col) offset += 1 # if j == 0: # boxes.append(plt.Rectangle((0, 0), 1, 1, fc=col)) # lbls.append(k) max_x = offset plt.text(min_x + (max_x - min_x) / 2., 1., k, ha='center') plt.title('N=%d' % len(dat)) plt.xticks(xvals, xaxis, rotation='vertical') plt.plot([-1, len(xaxis) + 1], [0, 0], '--') plt.xlim(0, offset) plt.ylim(-0.05, 1) plt.subplots_adjust(left=0.05, bottom=0.5, right=0.97, top=0.95, wspace=0.3, hspace=0.34) plt.legend(boxes, lbls, frameon=False, loc=4) plt.ylabel('Correlation between prediction and Experimental Mean') fname = '%s%s_pred_%s' % (fig_path, 'summary', extras) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') #plt.show() plt.close(fig)
def plot_bar_weights(weights, labels, ylims, plt_num=[1, 1, 1]): """ plot some weights (luminance, contrast, flow strength) on a bar chart """ ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) plt.hold(True) plt.bar(range(len(weights)), weights) ax.set_xticks(np.arange(len(weights)) + 0.5) ax.set_xticklabels(labels) plt.ylim(ylims) adjust_spines(ax, ['bottom', 'left']) plt.title('Other Weights')
def plot_summary(comb_corrs, targets, fig_path, extras=''): """ plot a summary showing the mean and std for all attempted combinations""" fig = plt.figure(figsize=(14, 12)) ax = plt.subplot(111) adjust_spines(ax, ['bottom', 'left']) colors = ['r', 'b', 'g', 'y', 'c', 'm'] _ = plt.subplot(111) xaxis = [] boxes = [] lbls = [] #targets.append('Overall') for i, [comb, vals] in enumerate(comb_corrs): xaxis.append(comb) offset = 0 for j, targ in enumerate(targets): dat = vals[targ] if len(dat) == 0: continue if targ == 'Overall': col = '0.3' else: col = colors[j] do_box_plot(np.array(dat), np.array([i + offset]), col, widths=[0.2]) #do_spot_scatter_plot(np.array(dat), np.array([i + offset]), col) offset += 0.3 if i == 0: boxes.append(plt.Rectangle((0, 0), 1, 1, fc=col)) lbls.append(targ) if j == 0: plt.title('N=%d' % len(dat)) plt.xticks(range(len(xaxis)), xaxis, rotation='vertical') plt.xlim(-1, len(xaxis) + 1) plt.plot([-1, len(xaxis) + 1], [0, 0], '--') plt.ylim(0, 1) plt.subplots_adjust(left=0.05, bottom=0.5, right=0.97, top=0.95, wspace=0.3, hspace=0.34) plt.legend(boxes, lbls, frameon=False, loc=4) plt.ylabel('Correlation between prediction and Experimental Mean') fname = '%s%s_pred_%s' % (fig_path, 'summary', extras) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') #plt.show() plt.close(fig)
def plot_prediction(pred, actual, title, plt_num=[1, 1, 1]): """ plot the prediction of the model vs the mean of the actual experiment """ ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) plt.hold(True) #plt.fill_between(range(len(pred)), actual, pred, facecolor=clr3) plt.plot(range(len(pred)), pred, color=clr4, linewidth=2, label='Predicted') plt.plot(range(len(pred)), actual, color=clr1, label='Mean Experimental', linewidth=2) plt.legend(bbox_to_anchor=(0.55, 0.95, 0.4, 0.1), frameon=False) adjust_spines(ax, ['bottom', 'left']) plt.title(title)
def plot_four(four_weights, ylims, plt_num=[1, 1, 1], title=None, ax_off=False, interpolation='None'): """plot the weights of the spatial fourier """ ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) ext = four_weights.shape[0] / 2. _ = plt.imshow(four_weights.T, cmap=plt.cm.gray, interpolation=interpolation, extent=(-ext, ext, -ext, ext)) plt.clim(ylims) if ax_off: adjust_spines(ax, []) else: adjust_spines(ax, ['bottom', 'left']) if title is None: title = 'Filter' plt.title(title)
def plot_four(four_weights, ylims, plt_num=[1, 1, 1], title=None, ax_off=False, interpolation='None'): """plot the weights of the spatial fourier """ ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) ext = four_weights.shape[0] / 2. im = plt.imshow(four_weights.T, cmap=plt.cm.gray, interpolation=interpolation, extent=(-ext, ext, -ext, ext)) plt.clim(ylims) if ax_off: adjust_spines(ax, []) else: adjust_spines(ax, ['bottom', 'left']) plt.xlabel('Cycles/Patch', fontsize='large') plt.ylabel('Cycles/Patch', fontsize='large') if title is None: title = 'Spatial Fourier Weights' plt.title(title)
def plot_movie(lum, con, flow, four, movie, fname): num_frames = lum.shape[1] fig = plt.figure(figsize=(16, 7)) fig.set_facecolor('white') ax = plt.subplot(231) plt.plot(lum[0]) plt.xlim(0, num_frames) plt.title('Luminence') adjust_spines(ax, ['left', 'bottom']) ax = plt.subplot(234) plt.plot(con[0]) plt.xlim(0, num_frames) plt.title('Contrast') adjust_spines(ax, ['left', 'bottom']) total_plots = 4 frames = np.linspace(0, num_frames - 1, total_plots).astype(np.int) print 'plotting frames ', frames four = np.abs(four) ** 2 lims = [four[0, frames].min(), four[0, frames].max()] for i, _ in enumerate(frames): ax = plt.subplot(3, 6, 3 + i, aspect='equal') plt.imshow(movie[0, i].T, cmap=plt.cm.gray) adjust_spines(ax, []) if i == 0: plt.title('Movie') ax = plt.subplot(3, 6, 9 + i, aspect='equal') plt.imshow(four[0, i].T, cmap=plt.cm.gray, interpolation='None') plt.clim(lims) if i == 0: adjust_spines(ax, ['left', 'bottom']) plt.title('Spatial Fourier') plt.xticks(np.linspace(0, four[0, i].shape[1], 4).astype(np.int)) plt.yticks(np.linspace(0, four[0, i].shape[0], 4).astype(np.int)) plt.colorbar() else: adjust_spines(ax, []) if len(flow) > 0: ax = plt.subplot(3, 6, 15 + i, polar=True) plt.plot([0, flow[0, i, 0]], [0, flow[0, i, 1]], '-o', color='0.3', linewidth=2) plt.ylim(0, flow[0, :, 1].max()) for _, spine in ax.spines.iteritems(): spine.set_color('none') # don't draw spine #plt.adjust_spines(ax,[]) if i != 0: plt.gca().set_yticklabels([]) plt.gca().set_xticklabels([]) else: plt.title('Flow') plt.xticks([0, np.pi / 2, np.pi, np.pi * 3. / 2]) plt.yticks(np.linspace(0, flow[0, :, 1].max(), 4).astype(np.int)) plt.subplots_adjust(left=0.04, bottom=0.06, right=0.96, top=0.95, wspace=0.20, hspace=0.35) #adjust_spines(ax,[]) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') plt.close(fig)
fig.set_facecolor('white') clr_c = '0.3' clr_w = np.array([79, 79, 217]) / 255. ax = plt.subplot(421) plt.hold(True) plt.fill_between(range(len(std_c)), mn_c - std_c, mn_c + std_c, facecolor='0.9') plt.plot(range(len(std_c)), mn_c, color=clr_c, label='Center', linewidth=2) plt.legend(bbox_to_anchor=(0.55, 0.95, 0.4, 0.1), frameon=False, ncol=2) plt.text(5, plt.ylim()[1] * 0.9, 'corr trl-trl: %.2f, #cells: : %d, #trials: %d' % (xcorr_c, dat_c.shape[0], dat_c.shape[2])) adjust_spines(ax, ['bottom', 'left']) ax = plt.subplot(422) plt.hold(True) plt.fill_between(range(len(std_w)), mn_w - std_w, mn_w + std_w, facecolor='0.9') plt.plot(range(len(std_w)), mn_w, color=clr_w, label='Whole Field', linewidth=2) plt.legend(bbox_to_anchor=(0.55, 0.95, 0.4, 0.1), frameon=False, ncol=2) plt.text(5, plt.ylim()[1] * 0.9, 'corr trl-trl: %.2f, #cells: : %d, #trials: %d' % (xcorr_w, dat_w.shape[0], dat_w.shape[2])) adjust_spines(ax, ['bottom', 'left']) plt.title('Mean & STD')
def plot_surround(lum, con, flow, four, movie, fname): num_frames = lum.shape[1] fig = plt.figure(figsize=(16, 9)) fig.set_facecolor('white') four = np.abs(four)**2 parts = lum.shape[0] time = np.arange(0, num_frames, 20) for s in range(parts): ax = plt.subplot(5, parts, s + 1) plt.plot(lum[s]) plt.xlim(0, num_frames) if s == 0: plt.title('Luminence') plt.xticks(time) adjust_spines(ax, ['left', 'bottom']) ax = plt.subplot(5, parts, parts + (s + 1)) plt.plot(con[s]) plt.xlim(0, num_frames) if s == 0: plt.title('Contrast') plt.xticks(time) adjust_spines(ax, ['left', 'bottom']) frame = num_frames / 2 lims = [four[s, frame].min(), four[s, frame].max()] ax = plt.subplot(5, parts, 2 * parts + (s + 1), aspect='equal') plt.imshow(movie[s, frame].T, cmap=plt.cm.gray) adjust_spines(ax, []) if s == 0: plt.title('Movie') ax = plt.subplot(5, parts, 3 * parts + (s + 1), aspect='equal') plt.imshow(four[s, frame].T, cmap=plt.cm.gray, interpolation='None') plt.clim(lims) if s == 0: adjust_spines(ax, ['left', 'bottom']) plt.title('Spatial Fourier') tix = np.array(plt.xticks()[0], dtype=np.float) plt.xticks(np.linspace(tix.min(), tix.max(), 4).astype(np.int)) tix = np.array(plt.yticks()[0]) plt.yticks(np.linspace(tix.min(), tix.max(), 4).astype(np.int)) #plt.colorbar() else: adjust_spines(ax, []) if len(flow) > 0: ax = plt.subplot(5, parts, 4 * parts + (s + 1), polar=True) plt.plot([0, flow[s, frame, 0]], [0, flow[s, frame, 1]], '-o', color='0.3', linewidth=2) for _, spine in ax.spines.iteritems(): spine.set_color('none') # don't draw spine if s != 0: plt.gca().set_yticklabels([]) plt.gca().set_xticklabels([]) else: plt.title('Flow') plt.xticks([0, np.pi / 2, np.pi, np.pi * 3. / 2]) plt.yticks( np.linspace(0, flow[s, frame, 1].max(), 4).astype(np.int)) plt.subplots_adjust(left=0.04, bottom=0.06, right=0.96, top=0.95, wspace=0.50, hspace=0.5) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') plt.close(fig)
def plot_movie(lum, con, flow, four, movie, fname): num_frames = lum.shape[1] fig = plt.figure(figsize=(16, 7)) fig.set_facecolor('white') ax = plt.subplot(231) plt.plot(lum[0]) plt.xlim(0, num_frames) plt.title('Luminence') adjust_spines(ax, ['left', 'bottom']) ax = plt.subplot(234) plt.plot(con[0]) plt.xlim(0, num_frames) plt.title('Contrast') adjust_spines(ax, ['left', 'bottom']) total_plots = 4 frames = np.linspace(0, num_frames - 1, total_plots).astype(np.int) print 'plotting frames ', frames four = np.abs(four)**2 lims = [four[0, frames].min(), four[0, frames].max()] for i, _ in enumerate(frames): ax = plt.subplot(3, 6, 3 + i, aspect='equal') plt.imshow(movie[0, i].T, cmap=plt.cm.gray) adjust_spines(ax, []) if i == 0: plt.title('Movie') ax = plt.subplot(3, 6, 9 + i, aspect='equal') plt.imshow(four[0, i].T, cmap=plt.cm.gray, interpolation='None') plt.clim(lims) if i == 0: adjust_spines(ax, ['left', 'bottom']) plt.title('Spatial Fourier') plt.xticks(np.linspace(0, four[0, i].shape[1], 4).astype(np.int)) plt.yticks(np.linspace(0, four[0, i].shape[0], 4).astype(np.int)) plt.colorbar() else: adjust_spines(ax, []) if len(flow) > 0: ax = plt.subplot(3, 6, 15 + i, polar=True) plt.plot([0, flow[0, i, 0]], [0, flow[0, i, 1]], '-o', color='0.3', linewidth=2) plt.ylim(0, flow[0, :, 1].max()) for _, spine in ax.spines.iteritems(): spine.set_color('none') # don't draw spine #plt.adjust_spines(ax,[]) if i != 0: plt.gca().set_yticklabels([]) plt.gca().set_xticklabels([]) else: plt.title('Flow') plt.xticks([0, np.pi / 2, np.pi, np.pi * 3. / 2]) plt.yticks(np.linspace(0, flow[0, :, 1].max(), 4).astype(np.int)) plt.subplots_adjust(left=0.04, bottom=0.06, right=0.96, top=0.95, wspace=0.20, hspace=0.35) #adjust_spines(ax,[]) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') plt.close(fig)
fig5 = plt.figure(figsize=(14, 8)) plt.hold(True) cnt = 1 for exp_type in exp_types: for k in stim_types: ax = plt.subplot(3, 2, cnt) plt.scatter(cell_max_time[exp_type][k][:, 0], cell_max_time[exp_type][k][:, 1], c='r', marker='x') # c=colors[i], marker=style[i]) plt.ylabel('corr of responders') if ax.is_last_row(): plt.xlabel('Shift in Frames') adjust_spines(ax, ['bottom', 'left']) else: adjust_spines(ax, ['left']) if ax.is_first_row(): plt.title(k) if ax.is_first_col(): ax.text(-0.12, 0.5, exp_type, transform=ax.transAxes, rotation='vertical', va='center', ha='center') adjuster = np.array([-0.5, 0.5]) ax.set_ylim(-0.05, 1) ax.set_xlim(np.array([shifts.min(), shifts.max()]) + adjuster)
def plot_corrs(c_vals, w_vals, mn_c_crr, mn_w_crr, n_cells, header, fname): fig = plt.figure(figsize=(14, 8)) fig.set_facecolor('white') c_vals = average_corrs(c_vals) w_vals = average_corrs(w_vals) c_vals_mn = average_corrs(c_vals) w_vals_mn = average_corrs(w_vals) mn_c_vals_mn = average_corrs(mn_c_crr) mn_w_vals_mn = average_corrs(mn_w_crr) print mn_c_crr.min(), mn_c_crr.max() # ax = plt.subplot(411) # plt.hold(True) # plt.plot(c_vals.T, '0.8') # plt.plot(c_vals_mn, '0.4', linewidth=2) # plt.xlim(0, c_vals.shape[1]) # adjust_spines(ax, ['bottom', 'left']) # plt.title('Masked') # plt.ylabel('Mean R') # # ax = plt.subplot(412) # plt.hold(True) # plt.plot(w_vals.T, '0.8') # plt.plot(w_vals_mn, '0.4', linewidth=2) # plt.xlim(0, w_vals.shape[1]) # adjust_spines(ax, ['bottom', 'left']) # plt.title('Whole Field') # plt.ylabel('Mean R') # # ax = plt.subplot(413) # plt.hold(True) # plt.plot(w_vals_mn, 'g', linewidth=2, label='Whole') # plt.plot(c_vals_mn, 'k', linewidth=2, label='Centre') # crr = do_thresh_corr(w_vals_mn, c_vals_mn) # leg = plt.legend(ncol=2) # leg.draw_frame(False) # plt.xlim(0, c_vals.shape[1]) # adjust_spines(ax, ['bottom', 'left']) # plt.ylabel('Mean R') # plt.xlabel('Sample') # plt.title('Whole vs Masked: Crr: {0:.2f}'.format(crr)) ax = plt.subplot(211) plt.hold(True) plt.plot(mn_w_vals_mn, 'g', linewidth=2, label='Whole') plt.plot(mn_c_vals_mn, 'k', linewidth=2, label='Centre') crr = do_thresh_corr(mn_w_vals_mn, mn_c_vals_mn) leg = plt.legend(ncol=2) leg.draw_frame(False) plt.xlim(0, c_vals.shape[1]) adjust_spines(ax, ['bottom', 'left']) plt.title('Mean Whole vs Masked: R^2: {0:.2f}'.format(crr)) plt.ylabel('Mean R') plt.xlabel('Sample') ax = plt.subplot(212) plt.hold(True) plt.plot(mn_c_vals_mn - mn_w_vals_mn, '0.3', linewidth=2) leg.draw_frame(False) plt.xlim(0, c_vals.shape[1]) adjust_spines(ax, ['bottom', 'left']) plt.title('Difference - Mean Whole vs Masked') plt.ylabel('Mean R') plt.xlabel('Sample') plt.suptitle('%s - Intercell R^2 over Trials - #Cells: %d' % (header, n_cells)) plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.9, wspace=0.2, hspace=0.25) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') #plt.show() plt.close(fig) print fname print n_cells print '\tMean\tMax' print 'Centre:\t%.3f\t%.3f' % (c_vals_mn.mean(), c_vals.max()) print 'Whole:\t%.3f\t%.3f' % (w_vals.mean(), w_vals.max()) print
def plot_cell_summary(res, fig_path, extras=''): colors = ['0.5', '0.05', 'k', 'r', 'g', 'y', 'c', 'm'] summary = [] for cnum, cell in enumerate(sorted(res.keys())): vals = [] maxes = {} x = 0 lbls = [] xtcks = [] fig = plt.figure(figsize=(14, 12)) ax = plt.subplot(111) plt.hold(True) for cmb in sorted(res[cell].keys()): x += 1 plt.text(x, 0.95, cmb, rotation=60, verticalalignment='bottom') for i, k in enumerate(sorted(res[cell][cmb])): val = res[cell][cmb][k]['crr_pred'] lbls.append(k) if k in maxes: if val > maxes[k][1]: maxes[k] = [cmb, val] else: maxes[k] = [cmb, val] xtcks.append(x) plt.plot([x, x], [0, val], ':', color='0.3') plt.scatter(x, val, c=colors[i], s=200) x += 1 if val > 0: vals.append([cmb, '%s' % (k), '%.2f' % val]) x += 2 plt.plot([0, x], [0, 0], '--') plt.xlim(0, x) plt.ylim(0, 1) plt.xticks(xtcks, lbls, rotation='vertical') adjust_spines(ax, ['bottom', 'left']) plt.ylabel('Prediction Correlation to Experimental Mean') plt.subplots_adjust(left=0.05, bottom=0.15, right=0.97, top=0.92, wspace=0.3, hspace=0.34) fig.savefig(fig_path + 'summary_' + cell + '.eps') fig.savefig(fig_path + 'summary_' + cell + '.png') plt.close(fig) f = open(fig_path + 'summary_' + cell + '.csv', 'w') if len(vals) == 0: vals.append(['', '', '']) for v in vals: f.write("\t".join(v)) f.write('\n') f.close() line2 = '%s\t' % cell line1 = '\t' for mm in sorted(maxes.keys()): line1 += '%s\t\t' % mm if maxes[mm][1] > 0: line2 += '%.2f\t%s\t' % (maxes[mm][1], maxes[mm][0]) else: line2 += '\t\t' if cnum == 0: summary.append(line1 + '\n') summary.append(line2 + '\n') f = open(fig_path + 'summary_all.csv', 'w') for l in summary: f.write(l) f.close()
mn_c + std_c, facecolor='0.9') plt.plot(range(len(std_c)), mn_c, color=clr_c, label='Center', linewidth=2) plt.legend(bbox_to_anchor=(0.55, 0.95, 0.4, 0.1), frameon=False, ncol=2) plt.text( 5, plt.ylim()[1] * 0.9, 'corr trl-trl: %.2f, #cells: : %d, #trials: %d' % (xcorr_c, dat_c.shape[0], dat_c.shape[2])) adjust_spines(ax, ['bottom', 'left']) ax = plt.subplot(422) plt.hold(True) plt.fill_between(range(len(std_w)), mn_w - std_w, mn_w + std_w, facecolor='0.9') plt.plot(range(len(std_w)), mn_w, color=clr_w, label='Whole Field', linewidth=2) plt.legend(bbox_to_anchor=(0.55, 0.95, 0.4, 0.1), frameon=False, ncol=2)
def plot_cell_summary(res, fig_path, extras=''): colors = ['0.5', '0.05', 'k', 'r', 'g', 'y', 'c', 'm'] summary = [] for cnum, cell in enumerate(sorted(res.keys())): vals = [] maxes = {} x = 0 lbls = [] xtcks = [] fig = plt.figure(figsize=(14, 12)) ax = plt.subplot(111) plt.hold(True) for comb in sorted(res[cell].keys()): x += 1 plt.text(x, 0.95, comb, rotation=60, verticalalignment='bottom') for i, targ in enumerate(sorted(res[cell][comb].keys())): for src in sorted(res[cell][comb][targ].keys()): val = res[cell][comb][targ][src] targ_src = '%s_%s' % (targ, src) lbls.append(targ_src) if targ_src in maxes: if val > maxes[targ_src][1]: maxes[targ_src] = [comb, val] else: maxes[targ_src] = [comb, val] xtcks.append(x) plt.plot([x, x], [0, val], ':', color='0.3') plt.scatter(x, val, c=colors[i], s=200) x += 1 vals.append([comb, '%s_%s' % (targ, src), '%.2f' % val]) x += 2 plt.plot([0, x], [0, 0], '--') plt.xlim(0, x) plt.ylim(0, 1) plt.xticks(xtcks, lbls, rotation='vertical') adjust_spines(ax, ['bottom', 'left']) plt.ylabel('Prediction Correlation to Experimental Mean') plt.subplots_adjust(left=0.05, bottom=0.2, right=0.97, top=0.7, wspace=0.3, hspace=0.34) fig.savefig(fig_path + 'summary_' + cell + '.eps') fig.savefig(fig_path + 'summary_' + cell + '.png') plt.close(fig) f = open(fig_path + 'summary_' + cell + '.csv', 'w') for v in vals: f.write("\t".join(v)) f.write('\n') f.close() line2 = '%s\t' % cell line1 = '\t' for mm in sorted(maxes.keys()): line1 += '%s\t\t' % mm line2 += '%.2f\t%s\t' % (maxes[mm][1], maxes[mm][0]) if cnum == 0: summary.append(line1 + '\n') summary.append(line2 + '\n') f = open(fig_path + 'summary_all.csv', 'w') for l in summary: f.write(l) f.close()
def plot_surround(lum, con, flow, four, movie, fname): num_frames = lum.shape[1] fig = plt.figure(figsize=(16, 9)) fig.set_facecolor('white') four = np.abs(four) ** 2 parts = lum.shape[0] time = np.arange(0, num_frames, 20) for s in range(parts): ax = plt.subplot(5, parts, s + 1) plt.plot(lum[s]) plt.xlim(0, num_frames) if s == 0: plt.title('Luminence') plt.xticks(time) adjust_spines(ax, ['left', 'bottom']) ax = plt.subplot(5, parts, parts + (s + 1)) plt.plot(con[s]) plt.xlim(0, num_frames) if s == 0: plt.title('Contrast') plt.xticks(time) adjust_spines(ax, ['left', 'bottom']) frame = num_frames / 2 lims = [four[s, frame].min(), four[s, frame].max()] ax = plt.subplot(5, parts, 2 * parts + (s + 1), aspect='equal') plt.imshow(movie[s, frame].T, cmap=plt.cm.gray) adjust_spines(ax, []) if s == 0: plt.title('Movie') ax = plt.subplot(5, parts, 3 * parts + (s + 1), aspect='equal') plt.imshow(four[s, frame].T, cmap=plt.cm.gray, interpolation='None') plt.clim(lims) if s == 0: adjust_spines(ax, ['left', 'bottom']) plt.title('Spatial Fourier') tix = np.array(plt.xticks()[0], dtype=np.float) plt.xticks(np.linspace(tix.min(), tix.max(), 4).astype(np.int)) tix = np.array(plt.yticks()[0]) plt.yticks(np.linspace(tix.min(), tix.max(), 4).astype(np.int)) #plt.colorbar() else: adjust_spines(ax, []) if len(flow) > 0: ax = plt.subplot(5, parts, 4 * parts + (s + 1), polar=True) plt.plot([0, flow[s, frame, 0]], [0, flow[s, frame, 1]], '-o', color='0.3', linewidth=2) for _, spine in ax.spines.iteritems(): spine.set_color('none') # don't draw spine if s != 0: plt.gca().set_yticklabels([]) plt.gca().set_xticklabels([]) else: plt.title('Flow') plt.xticks([0, np.pi / 2, np.pi, np.pi * 3. / 2]) plt.yticks(np.linspace(0, flow[s, frame, 1].max(), 4).astype(np.int)) plt.subplots_adjust(left=0.04, bottom=0.06, right=0.96, top=0.95, wspace=0.50, hspace=0.5) fig.savefig(fname + '.eps') fig.savefig(fname + '.png') plt.close(fig)
fig = plt.figure(figsize=(7, 4)) fig.set_facecolor('white') ax = plt.subplot(111) plt.suptitle(label) plt.hold(True) #plt.plot(dt.T, '0.7') mn_cell = dt.mean(0) mn_cell = (mn_cell - mn_cell.mean()) / np.std(mn_cell) mn_pred = (pred[cell] - pred[cell].mean()) / np.std(pred[cell]) plt.plot(mn_cell, 'k', lw=2, label='Ephys Cell (Mean)') plt.plot(mn_pred, 'r', label='aTRBM Cell') plt.ylabel('Normalised Activation') plt.xlabel('Sample') plt.legend(bbox_to_anchor=(0.1, 0, 0.15, 0.91), bbox_transform=plt.gcf().transFigure, frameon=False, prop={'size':10}) plt.subplots_adjust(left=0.28, bottom=0.11, right=0.96, top=0.88, wspace=0.25, hspace=0.25) adjust_spines(ax, ['left', 'bottom']) fig.savefig(fig_path + '/cells/%s.eps' % (fname)) fig.savefig(fig_path + '/cells/%s.png' % (fname)) #plt.show() plt.close(fig) print mx bins = np.linspace(0, mx + 0.05, 10) print bins for rbm_type in new_res: fig = plt.figure(figsize=(20, 14)) fig.set_facecolor('white') plt.suptitle('%s' % (rbm_type)) rows = len(exp_type) * len(new_res[rbm_type]) cols = len(shifts)
def plot_preds_freq(weights, plt_num=[1, 1, 1]): ax = plt.subplot(plt_num[0], plt_num[1], plt_num[2]) plt.scatter(range(len(weights)), weights) adjust_spines(ax, ['bottom', 'left'])