def plot_good_cell_connections(self, fig_cnt=1): ax = self.fig.add_subplot(self.n_fig_y, self.n_fig_x, fig_cnt) for gid in self.good_gids: x, y, u, v = self.tuning_prop[gid] thetas = np.arctan2(v, u) h = ((thetas + np.pi) / (2 * np.pi)) * 360. # theta determines h, h must be [0, 360) l = np.sqrt(u**2 + v**2) / np.sqrt(2 * self.params['v_max_tp']**2) # lightness [0, 1] s = 1. # saturation assert (0 <= h and h < 360) assert (0 <= l and l <= 1) assert (0 <= s and s <= 1) (r, g, b) = utils.convert_hsl_to_rgb(h, s, l) ax.plot(x, y, 'o', c=(r,g,b), markersize=7, markeredgewidth=0)#, edgecolors=None) ax.set_xlabel('X-position') ax.set_ylabel('Y-position')
def plot_cells_by_euclidean_tuning_distance(subplot_code=111, direction=False): def get_dist(x, y): d = 0. for i in xrange(len(x)): d += (x[i] - y[i])**2 dist = np.sqrt(d) return dist ax2 = fig.add_subplot(subplot_code) dist = np.zeros(len(tgts_ee)) for i_, tgt in enumerate(tgts_ee): x_tgt, y_tgt, u_tgt, v_tgt = tp_exc[tgt, :] if direction: x = (u_tgt, v_tgt) y = (u0, v0) else: x = (x_tgt, y_tgt, u_tgt, v_tgt) y = (x0, y0, u0, v0) dist[i_] = get_dist(x, y) #sorted_idx = np.argsort(dist) dist_min, dist_max = dist.min(), dist.max() print 'direction %s, dist_min=%.2e dist_max=%.2e' % (str(direction), dist_min, dist_max) for i in xrange(dist.size): x_tgt, y_tgt, u_tgt, v_tgt = tp_exc[i, :] h = 0 l = (dist[i] - dist_min) / (dist_max - dist_min) s = 0. # saturation assert (0 <= h and h < 360) assert (0 <= l and l <= 1) assert (0 <= s and s <= 1) (r, g, b) = utils.convert_hsl_to_rgb(h, s, l) x, y, u, v = tp_exc[i, :] ax2.plot(x, y, 'o', c=(r,g,b), markersize=4) if with_annotations: ax2.annotate('(%d, %.2e, %.2e)' % (tgt, w, d), (x_tgt, y_tgt), fontsize=8) if direction: ax2.set_title('Distance to cell %d\nin direction space' % (exc_cell)) else: ax2.set_title('Euclidean distance to cell %d\nin tuning_prop space' % (exc_cell)) ax2.set_xlabel('x position') ax2.set_ylabel('y position') return ax2
fig1 = plt.figure() n_frames = activity[:, 0].size pos = np.zeros((n_cells, 2)) pos[:, 0], pos[:, 1] = tp[:, 0], tp[:, 1] colors = np.zeros((n_frames, n_cells, 3)) s = 1.0 # saturation for frame in xrange(n_frames): for cell in xrange(n_cells): if activity[frame, cell] < 0: l = 1.0 - 0.5 * activity[frame, cell] / activity_min h = 0.0 else: l = 1.0 - 0.5 * activity[frame, cell] / activity_max h = 240.0 assert 0 <= h and h < 360 assert 0 <= l and l <= 1 assert 0 <= s and s <= 1 (r, g, b) = utils.convert_hsl_to_rgb(h, s, l) colors[frame, cell, :] = [r, g, b] dot_ani = animation.FuncAnimation(fig1, paint_dots, n_frames, fargs=(pos, colors), interval=50, blit=True) output_fn = "dynamic_images.mp4" print "Saving movie", output_fn dot_ani.save(output_fn) print "Finished" # plt.show()