Example #1
0
File: Maze.py Project: r-b-g-b/Lab
def plot_trial(dat, info, ax = None):
	
	ax, _ = misc.axis_check(ax)
	
	# plot the pre-track
	plot_track(dat['pre_x'], dat['pre_y'], ax = ax, color = 'b')
	ax.plot(dat['pre_x'][0], dat['pre_y'][0], marker = '*', ms = 20, color = 'b')

	# if there is a post-track, plot it
	if len(dat['post_x']) > 0:
		plot_track(dat['post_x'], dat['post_y'], ax = ax, color = 'g')
		ax.plot(dat['post_x'][0], dat['post_y'][0], marker = '*', ms = 20, color = 'g')

	# draw the target radius
	cir = mpl.patches.Circle((dat['target_x'], dat['target_y']), radius = info['target_radius'], color = 'r', fill = False, linestyle = 'dotted')
	ax.add_patch(cir)
	
	# draw the arena radius
	cir = mpl.patches.Circle((info['arena_x'], info['arena_y']), radius = info['arena_radius'], color = 'k', fill  = False)
	ax.add_patch(cir)
	misc.target(dat['target_x'], dat['target_y'], ax, color = 'r')
	misc.target(dat['spout_x'], dat['spout_y'], ax, color = 'g')
	
	# set the axis limits
	ax.set_xlim([info['arena_x']-info['arena_radius']-20, info['arena_x']+info['arena_radius']+20])
	ax.set_ylim([info['arena_y']-info['arena_radius']-20, info['arena_y']+info['arena_radius']+20])
	
	plt.show()
Example #2
0
File: RR.py Project: r-b-g-b/Lab
def circ_psth(rast_, rr, npips, onset = 0.05, bins = 20, color = 'b', remove_first = False, ax = None):
	'''
	Input:
		rast_ : subset of block raster corresponding to only the stimuli you want plotted
		rr : the repetition rate
		npips : number of pips presented at this rate
		onset : in seconds, onset time of first pip
		bins : number of bins to include
		remove_first : exclude the respose to the first pip
	'''
	
	spktimes_ = Spikes.rast2spktimes(rast_)
	period = 1. / rr
	train_end = float(npips) / rr
	spktimes_chunk = spktimes_ - onset
	spktimes_chunk = spktimes_chunk[spktimes_chunk > 0]
	spktimes_chunk = spktimes_chunk[spktimes_chunk < train_end]
	if remove_first:
		spktimes_chunk = spktimes_chunk[spktimes_chunk > period]
	spktimes_pol = spktimes_chunk * 2*np.pi * rr # convert to radians
	spktimes_pol = np.mod(spktimes_pol, 2*np.pi) # force range 0-2pi
	nspks = spktimes_pol.size

	r, V, theta = circ_stat(spktimes_pol)
	
	ax, fig = misc.axis_check(ax, polar = True)
	if spktimes_pol.size > 0:
		ax.hist(spktimes_pol, bins = bins, color = color, histtype = 'stepfilled')
		ax.plot([0, theta], [0, V], 'r.-')
		ax.plot([0, 0], [0, V*np.cos(theta)], 'r.-')

	return r, V, theta
Example #3
0
File: Maze.py Project: r-b-g-b/Lab
def plot_heatmap(data, epoch = 'pre', ax = None, gridsize = 30, rel_to_target = False):
	'''
	plots a heatmap from x and y locations in one of the trial epochs.
	uses hexagonal bins
	'''
	xy = np.empty((0, 2), dtype = np.int32)
	x_key = epoch + '_x'
	y_key = epoch + '_y'
	if rel_to_target is True:
		for dat in data:
			xy = np.vstack((xy, np.vstack((dat[x_key] - dat['target_x'], dat[y_key] - dat['target_y'])).T))

	elif rel_to_target is False:
		for dat in data:
			xy = np.vstack((xy, np.vstack((dat[x_key], dat[y_key])).T))
	
	ax, _ = misc.axis_check(ax)
	
	ax.set_aspect('equal')
	ax.hexbin(xy[:, 0], xy[:, 1], gridsize = gridsize)
	
	if rel_to_target is False:
		misc.target(data[0]['spout_x'], data[0]['spout_y'], ax)
	if rel_to_target is True:
		misc.target(0, 0, ax)

	plt.show();
Example #4
0
File: voc.py Project: r-b-g-b/Lab
def plot_blob(blob, Pxx, ax = None):
	
	ax, fig = misc.axis_check(ax)
	
	plot_spec(np.power(Pxx, 0.5), ax = ax)
	ax.set_xlim((max(blob['ij'][0][1] - 100, 0), blob['ij'][-1][1]+100))
	plt.show()
Example #5
0
File: voc.py Project: r-b-g-b/Lab
def plot_spec(Pxx, F = None, T = None, ax = None, F_range = None, **kwargs):
	'''
	Plots and correctly formats the spectrogram (axis tick labels)
	Input:
		Pxx : MxN spectrogram array (M frequencies, N time bins)
		F : vector of length M indicating the frequencies included in the spectrogram
		ax : axis on which to plot
		lowpass : boolean, whether or not to exclude frequencies lower than 2 kHz
		kwargs : properties for plotting
	Output:
		ax : axis containing the spectrogram
	'''

	ax, fig = misc.axis_check(ax)
	
	if T is None:
		extent = [0, Pxx.shape[1]-1, None, None]
	else:
		extent = [T[0], T[-1], None, None]
		
	if F is None:
		extent[2:4] = [0, Pxx.shape[0]-1]
	else:
		extent[2:4] = [F[0], F[-1]]

	ax.imshow(Pxx, aspect = 'auto', origin = 'lower', interpolation = 'nearest', extent = extent, **kwargs)
	
	# ax.set_yticks(np.arange(0, F.size, 20))
	# ax.set_yticklabels(F[np.arange(0, F.size, 20)])

	# fig.tight_layout()

	return ax
Example #6
0
File: Maze.py Project: r-b-g-b/Lab
def plot_track(x, y, ax = None, **kwargs):
	
	'''
	shows the path for one trial
	'''
	
	ax, _ = misc.axis_check(ax)
	ax.set_aspect('equal')
	
	ax.plot(x, y, '.-', **kwargs)
	plt.show()
Example #7
0
File: Gap.py Project: r-b-g-b/Lab
def plot_startleampl(df, ax = None):
    '''
    plots the startle amplitude as a function of trial number
    uncued: red
    cued: black
    '''
    if not hasattr(df, 'startleampl'):
        df = add_startleampl(df)

    ax, fig = misc.axis_check(ax)

    cuegp = df.groupby('cued')
    colors = dict(cued ='k', uncued='r')
    for i, j in cuegp:
        ax.plot(j.index, j.startleampl, '.', color = colors[i])
Example #8
0
def plot_raster(rast, lineheight = None, ax = None):
	
	ax, _ = misc.axis_check(ax)

	ntrials, nbins = rast.shape
	spk = rast.nonzero()
	spktrials = spk[0]
	spktimes = spk[1]/1000.
	
	ax.plot(spktimes, spktrials, marker = '|', linestyle = '', ms = 1)

	if not lineheight is None:
		[ax.axhline(i, color = 'r', lw = 0.5) for i in lineheight]

	ax.set_xlim([0, nbins/1000.])
	ax.set_ylim([0, ntrials])
	
	return ax
Example #9
0
def plot_hist2d(df, ax = None):
	ax, fig = misc.axis_check(ax)
	ax.hist2d(-df.LocY, df.LocX, bins = 1000)
	return ax
Example #10
0
def plot_loc(df, ax = None, color = 'b', ms = 0.5, **kwargs):
	ax, fig = misc.axis_check(ax)
	ax.plot(-df.LocY, df.LocX, '.', color = color, ms = ms, **kwargs)
	return ax
Example #11
0
File: RR.py Project: r-b-g-b/Lab
def plot_rrtf(t, psth, rr, npips, onset = 0.05, duration = 0.025, ax = None):

	ax, fig = misc.axis_check(ax)

	ax.plot(t, Spikes.exp_smoo(psth))
	plot_tone_pips(rr, npips, onset = onset, duration = duration, ax = ax, color = 'r')