-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
63 lines (47 loc) · 1.88 KB
/
Copy pathplotting.py
File metadata and controls
63 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import matplotlib.pyplot as plt
def convert_inches(inches):
'''converts an inch value to a centimeter'''
CM_PER_INCH = 2.54
inches = np.array(inches)
return inches * CM_PER_INCH
def raster_duration(array, start_trial = 0, ax = None, label = '', **kwargs):
'''Given a 3D list of on - off times in the form (trial x event x time)
plots a raster on a matplotlib axis.
Requires matplotlib to be imported and a plot to exist.'''
if ax is None:
ax = plt.gca()
for i, (t) in enumerate(array, start_trial):
for j, (up, down) in enumerate(zip(t[::2], t[1::2])):
ax.hlines(i + 0.5, up, down,
label = label if i + j == start_trial else '',
**kwargs)
def plot_raster(stim, lick, water,
start_trail = 0,
axes = plt.gca(),
start_trial = 0,
dt = 20000,
):
hit, miss, CR, FA = False, False, False, False
for i, (s, l, w) in enumerate(zip(stim, lick, water), start_trial):
# stimulus
if (s).nonzero()[0].any():
axes.hlines(i + 0.5, *(s).nonzero()[0]/dt,
color = 'mediumpurple',
lw = 2,
label = 'Stimulus' if not i else '',
);
# all licks
axes.vlines((l).nonzero()[0]/dt, i, i+1,
color = 'lightsalmon',
label = 'licks' if not i else '',
);
# water valve
axes.vlines((w).nonzero()[0]/dt, i, i+1,
color = 'RoyalBlue',
lw = 2,
label = 'Water valve' if not i else '',
);
axes.set_ylim(0,i+1);
axes.set_ylabel('trial');
axes.set_xlabel('time (s)');