def plotDiffusion(): m = np.random.randn(100, 200) random_walks = np.cumsum(m, axis=1) fig = plt.figure() ### ax = fig.add_subplot(231) for i in xrange(random_walks.shape[0]): ax.add_line(plt.Line2D( np.arange(random_walks.shape[1]), random_walks[i, :], color='k', alpha=.35)) misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Time (a.u.)') ax.set_ylabel('Magnitude (a.u.)') ax.set_xlim(0, 100) ax.set_ylim(-25, 25) ax = fig.add_subplot(234) ax.add_line(plt.Line2D( np.arange(random_walks.shape[1]), np.var(random_walks, axis=0), color='k')) misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Time (a.u.)') ax.set_ylabel('Variance') ax.set_xlim(0, 100) ax.set_ylim(0, 125) ### ax = fig.add_subplot(232) for i in xrange(random_walks.shape[0]): ax.add_line(plt.Line2D( np.arange(random_walks.shape[1]), random_walks[i, :], color='k', alpha=.35)) misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Time (a.u.)') ax.set_ylabel('Magnitude (a.u.)') ax.set_xlim(0, 100) ax.set_ylim(-25, 25) colors = ['red', 'green', 'blue'] ax.axvline(15, color='black') for i in np.arange(3): ax.axvline(15 + (i + 1) * 20, color=colors[i]) ax = fig.add_subplot(235) for i in np.arange(3)[::-1]: ax.scatter(random_walks[:, 15], random_walks[:, 15 + (i + 1) * 20], color=colors[i], alpha=.2, marker='o') ax.text(0.1, 0.9 - i * .05, 'r = %.2f' % pearsonr(random_walks[:, 15], random_walks[:, 15 + (i + 1) * 20])[0], transform=ax.transAxes, color=colors[i]) misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Magnitude (a.u.)') ax.set_ylabel('Magnitude (a.u.)') ax.set_xlim(-25, 25) ax.set_ylim(-25, 25) ### ax = fig.add_subplot(233) for i in xrange(random_walks.shape[0]): ax.add_line(plt.Line2D( np.arange(random_walks.shape[1]), random_walks[i, :], color='k', alpha=.35)) misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Time (a.u.)') ax.set_ylabel('Magnitude (a.u.)') ax.set_xlim(0, 100) ax.set_ylim(-25, 25) ax.axvline(10, color='orange') ax.axvline(40, color='orange') ax.axvline(30, color='cyan') ax.axvline(60, color='cyan') ax = fig.add_subplot(236) ax.scatter(random_walks[:, 10], random_walks[ :, 40], color='orange', alpha=.35, marker='o') ax.scatter(random_walks[:, 30], random_walks[ :, 60], color='cyan', alpha=.35, marker='o') ax.text(0.1, 0.9, 'r = %.2f' % pearsonr(random_walks[:, 10], random_walks[:, 40])[0], transform=ax.transAxes, color='orange') ax.text(0.1, 0.8, 'r = %.2f' % pearsonr(random_walks[:, 30], random_walks[:, 60])[0], transform=ax.transAxes, color='cyan') misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Magnitude (a.u.)') ax.set_ylabel('Magnitude (a.u.)') ax.set_xlim(-25, 25) ax.set_ylim(-25, 25) plt.tight_layout()
def plotCorCE(g, n_bins=8): fig = plt.figure() # find the best phi phis = findBestPhi( g['spk_counts'][:, 0:n_bins], g['count_means'][:, 0:n_bins], np.float64(g['trial_counts'][:, 0:n_bins]), min_trials=6) g_var = computeVarCorCovCE( g['spk_counts'][:, 0:n_bins], g['count_means'][:, 0:n_bins], g['trial_counts'][:, 0:n_bins], phis) ax = fig.add_subplot(121) cax = ax.imshow( g_var['corCE'], vmin=0, vmax=1, interpolation='nearest', cmap='jet') n_points = g_var['corCE'].shape[0] ax.set_xticks(np.arange(n_points)) ax.set_yticks(np.arange(n_points)) ax.set_xticklabels(g['spk_counts_times'], rotation=45) ax.set_yticklabels(g['spk_counts_times']) ax.add_line(plt.Line2D( np.arange(n_points)[1:], np.repeat(0, n_points)[1:], color='k')) ax.add_line(plt.Line2D( np.arange(n_points)[0:-1] + 1, np.arange(n_points)[0:-1], color='k', linestyle='--')) # vertically oriented colorbar cbar = fig.colorbar(cax, ticks=[0, 0.5, 1], shrink=0.2, aspect=4) cbar.ax.set_yticklabels(['0.0', '0.5', '1.0']) cbar.ax.set_ylabel('CorCE') # comparison with theory corCEPred = g_var['corCE'] n = corCEPred.shape[0] corCETheory = corCEpartialSums(n) ax = fig.add_subplot(122) x = np.arange(2, n + 1) ax.scatter( x, np.diagonal(corCEPred, 1), color='k', s=25, facecolors='none') ax.scatter(x, corCEPred[0, 1:], color='k', s=25) ax.add_line( plt.Line2D(x, np.diagonal(corCETheory, 1), color='k', linestyle='--')) ax.add_line(plt.Line2D(x, corCETheory[0, 1:], color='k')) misc.adjust_spines(ax, ['left', 'bottom']) ax.tick_params(axis='both', direction='out') ax.grid('on') ax.set_xlabel('Time (ms)') ax.set_ylabel('CorCE') ax.set_xticklabels(g['spk_counts_times']) ax.set_ylim(0.3, 1) plt.tight_layout()