-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fig1C_ExamplePlots_0100.py
402 lines (365 loc) · 29.7 KB
/
Fig1C_ExamplePlots_0100.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
"""
# PLOTS EXAMPLE TRAINING SESSIONS
For each mouse and day specified, the location of stops for each trial is calculated. From this, average stops per 10 cm location bins is plotted. In addition, the average speed along the track is plotted. One figure is produced for each mouse and day specified.
"""
# Import functions and packages
from Functions_Core_0100 import extractstops,filterstops,create_srdata, makebinarray, speed_per_trial, makelegend, makelegend2, makelegend3, makelegend4, shuffle_analysis_pertrial3, extractrewards, adjust_spines,readhdfdata, FirstStops, maketrialarray
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import math
from scipy.stats import uniform
# Load raw data: specify the HDF5 file to read data from
filename = 'Data_Input/Behaviour_DataFiles/Task13_0300.h5'
#specify mouse/mice and day/s to analyse
#days = ['Day' + str(int(x)) for x in np.arange(1,21.1)] # Several days
#mice = ['M' + str(int(x)) for x in np.arange(1,8.1)] # Several mice
mice = ['M' + str(int(x)) for x in [6]]# specific mice
days = ['Day' + str(int(x)) for x in [1,17]]# specific day/s
bins = np.arange(0.5,20.5,1) # array of bins for location
# For each day and mouse, pull raw data, calculate stops/speed and plot graph
for dcount,day in enumerate(days):
for mcount,mouse in enumerate(mice):
print ('Processing...',day,mouse)
try:
saraharray = readhdfdata(filename,day,mouse,'raw_data')#load HDF5 data set for that day and mouse
except KeyError: # if there is no datafile, skip that mouse & day
print ('Error, no file')
continue
trialno = np.max(saraharray[:,9]) # total number of trials for that day and mouse (used later for defining y axis max)
# make array of trial number for each row in dataset
trialarray = maketrialarray(saraharray)
saraharray[:,9] = trialarray[:,0] # replace trial column in dataset *see README for why this is done*
# Extract data for beaconed, non-beaconed, probe
dailymouse_b = np.delete(saraharray, np.where(saraharray[:, 8] > 0), 0) # delete all data not on beaconed tracks
dailymouse_nb = np.delete(saraharray, np.where(saraharray[:, 8] != 10), 0)# delete all data not on non beaconed tracks
dailymouse_p = np.delete(saraharray, np.where(saraharray[:, 8] != 20), 0)# delete all data not on probe tracks
#extract stops
stopsdata_b = extractstops(dailymouse_b)
stopsdata_nb = extractstops(dailymouse_nb)
stopsdata_p = extractstops(dailymouse_p)
#get location and trial number of rewards
reward_beac = extractrewards(dailymouse_b)
reward_nbeac = extractrewards(dailymouse_nb)
# filter stops (removes stops 0.5 cm after a stop)
stopsdata_b = filterstops(stopsdata_b)
stopsdata_nb = filterstops(stopsdata_nb)
stopsdata_p = filterstops(stopsdata_p)
# extract trial numbers from data (only unique ones)
trialids_b = np.unique(stopsdata_b[:, 2])
trialids_nb = np.unique(stopsdata_nb[:, 2])
if stopsdata_p.size > 0: # if there are probe trials
trialids_p = np.unique(stopsdata_p[:, 2])
# get mean stops per bin for real and shuffled data
srbin_mean_b, srbin_std_b,shuffled_mean_b, shuffled_std_b = shuffle_analysis_pertrial3(stopsdata_b, trialids_b)
srbin_mean_nb, srbin_std_nb, shuffled_mean_nb, shuffled_std_nb = shuffle_analysis_pertrial3(stopsdata_nb, trialids_nb)
if stopsdata_p.size > 0:
srbin_mean_p, srbin_std_p, shuffled_mean_p, shuffled_std_p = shuffle_analysis_pertrial3(stopsdata_p, trialids_p)
# calculate average speed
speed_beaconed = speed_per_trial(bins,saraharray,trialids_b)
speed_nbeaconed = speed_per_trial(bins,saraharray,trialids_nb)
if stopsdata_p.size>0: # if there are probe trials
speed_probe = speed_per_trial(bins,saraharray,trialids_p)
sd_speed_probe = np.nanstd(speed_probe,axis = 1)
sd_speed_beaconed = np.nanstd(speed_beaconed,axis = 1)
sd_speed_nbeaconed = np.nanstd(speed_nbeaconed,axis = 1)
speed_beaconed = np.nanmean(speed_beaconed,axis = 1)
speed_nbeaconed = np.nanmean(speed_nbeaconed,axis = 1)
if stopsdata_p.size>0: # if there are probe trials
speed_probe = np.nanmean(speed_probe,axis = 1)
# plot graphs:
try:
if stopsdata_p.size > 0: # if there are probe trials, plot 3x3 subplots
# MAKE FIGURE: 1st row: stop rasters. 2nd row: average stops. 3rd row: speed. Columns are beaconed/non-beaconed/probe
fig = plt.figure(figsize = (12,12))
ax = fig.add_subplot(3,3,1) #stops per trial
ax.set_title('Beaconed trials', fontsize = 22,verticalalignment = 'bottom', style = 'italic')
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', hatch = '/', linewidth =0, alpha=0.15) # black box
ax.axvspan(20-3, 20, facecolor='k', hatch = '/', linewidth =0, alpha=0.15)# black box
ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
ax.axhline(0, linewidth = 3, color = 'black') # bold line on the x axis
ax.plot(stopsdata_b[:,0],stopsdata_b[:,2], 'o', color = 'Black', markersize =4.5, label = 'Stop') #plot becaoned trials
ax.plot(reward_beac[:,0],reward_beac[:,2], '>', color = 'Red', markersize = 6, label = 'Reward') #plot becaoned trials
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0,20)
ax.set_ylim(0,trialno+0.5)
adjust_spines(ax, ['left','bottom']) # removes top and right spines
makelegend(fig,ax) # make legend
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_ylabel('Trial number', fontsize=18, labelpad = 20)
ax = fig.add_subplot(3,3,2) #stops per trial
ax.set_title('Non-beaconed trials', fontsize = 22, style = 'italic',verticalalignment = 'bottom')
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
ax.axhline(0, linewidth = 3, color = 'black') # bold line on the x axis
ax.plot(stopsdata_nb[:,0],stopsdata_nb[:,2], 'o',color = 'Black', markersize = 4.5) #plot becaoned trials
ax.plot(reward_nbeac[:,0],reward_nbeac[:,2], '>', color = 'Red', markersize = 6, label = 'Reward') #plot becaoned trials
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0,20)
ax.set_ylim(0,trialno+0.5)
adjust_spines(ax, ['left','bottom']) # re;moves top and right spines
makelegend(fig,ax) # makes legend
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_yticklabels(['', '', ''])
ax = fig.add_subplot(3,3,3) #stops per trial
ax.set_title('Probe trials', fontsize = 22, style = 'italic',verticalalignment = 'bottom')
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
ax.axhline(0, linewidth = 3, color = 'black') # bold line on the x axis
ax.plot(stopsdata_p[:,0],stopsdata_p[:,2], 'o',color = 'Black', markersize = 4.5, label = 'Non - beaconed') #plot becaoned trials
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0,20)
ax.set_ylim(0,trialno+0.5)
adjust_spines(ax, ['left','bottom']) # removes top and right spines
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_yticklabels(['', '', ''])
ax = fig.add_subplot(3,3,4)
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(-0.05, linewidth = 3, color = 'black')
ax.plot(bins, srbin_mean_b, color = 'red',linewidth=2) #plot becaoned trials
ax.fill_between(bins,srbin_mean_b-srbin_std_b,srbin_mean_b+srbin_std_b, facecolor = 'red', alpha = 0.3)
ax.plot(bins, shuffled_mean_b, '--',color = 'Black',linewidth=2) #plot becaoned trials
ax.fill_between(bins,shuffled_mean_b-shuffled_std_b,shuffled_mean_b+shuffled_std_b, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0, 20)
ax.set_ylim(-0.05,1.25)
adjust_spines(ax, ['left','bottom'])
ax.set_ylabel('Stops (cm/trial)', fontsize=18, labelpad = 23)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
#avg stops histogram - non beaconed
ax = fig.add_subplot(3,3,5)
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(-0.05, linewidth = 3, color = 'black')
ax.plot(bins,srbin_mean_nb, color = 'red',linewidth=2, label = 'Real') #plot becaoned trials
ax.fill_between(bins,srbin_mean_nb-srbin_std_nb,srbin_mean_nb+srbin_std_nb, facecolor = 'red', alpha = 0.3)
ax.plot(bins, shuffled_mean_nb,'--', color = 'Black',linewidth=2, label = 'Shuffled') #plot becaoned trials
ax.fill_between(bins,shuffled_mean_nb-shuffled_std_nb,shuffled_mean_nb+shuffled_std_nb, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
adjust_spines(ax, ['left','bottom'])
makelegend2(fig,ax) # makes legend
ax.set_xlim(0, 20)
ax.set_ylim(-0.05,1.25)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_yticklabels(['', '', '',''])
ax = fig.add_subplot(3,3,6)
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axhline(-0.05, linewidth = 3, color = 'black')
ax.axvline(0, linewidth = 3, color = 'black')
ax.plot(bins,srbin_mean_p,color = 'red',linewidth=2) #plot becaoned trials
ax.fill_between(bins,srbin_mean_p-srbin_std_p,srbin_mean_p+srbin_std_p, facecolor = 'red', alpha = 0.3)
ax.plot(bins, shuffled_mean_p, '--', color = 'Black',linewidth=2) #plot becaoned trials
ax.fill_between(bins,shuffled_mean_p-shuffled_std_p,shuffled_mean_p+shuffled_std_p, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
adjust_spines(ax, ['left','bottom'])
ax.set_xlim(0, 20)
ax.set_ylim(-0.05,1.25)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_yticklabels(['', '', '',''])
ax = fig.add_subplot(3,3,7)
ax.axvspan(44, 44+11, facecolor='g', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(0, linewidth = 3, color = 'black')
ax.plot(bins*5,speed_beaconed,'-',markersize = 2, color = 'Black',linewidth = 1) #plot becaoned trials
ax.fill_between(bins*5,speed_beaconed-sd_speed_beaconed,speed_beaconed+sd_speed_beaconed, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0, 101)
ax.set_ylim(0)
adjust_spines(ax, ['left','bottom'])
ax.set_ylabel('Speed (cm/s)', fontsize=18, labelpad = 20)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['-30', '100', '170'])
#avg stops histogram - non beaconed
ax = fig.add_subplot(3,3,8)
ax.axvspan(44, 44+11, facecolor='g', alpha=0.2, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.1, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.1, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(0, linewidth = 3, color = 'black')
ax.plot(bins*5,speed_nbeaconed, '-',markersize = 2,color = 'Black',linewidth = 1) #plot becaoned trials
ax.fill_between(bins*5,speed_nbeaconed-sd_speed_nbeaconed,speed_nbeaconed+sd_speed_nbeaconed, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
adjust_spines(ax, ['left','bottom'])
ax.set_xlim(0, 101)
ax.set_ylim(0)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_yticklabels(['', '', ''])
ax.set_xlabel('Location (cm)', fontsize=18, labelpad = 20)
ax = fig.add_subplot(3,3,9)
ax.axvspan(44, 44+11, facecolor='g', alpha=0.3, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.3, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.3, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(0, linewidth = 3, color = 'black')
ax.plot(bins*5,speed_probe, '-',markersize = 2, color = 'Black',linewidth = 1) #plot becaoned trials
ax.fill_between(bins*5,speed_probe-sd_speed_probe,speed_probe+sd_speed_probe, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
adjust_spines(ax, ['left','bottom'])
ax.set_xlim(0, 101)
ax.set_ylim(0)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_yticklabels(['', '', ''])
plt.subplots_adjust(hspace = .35, wspace = .35, bottom = 0.15, left = 0.07, right = 0.82, top = 0.92)
fig.savefig('Plots/Figure1/ExampleData/Example' + 'Data' + '_' + str(mouse) + '_' + str(day) + '.png', dpi = 200)
plt.close()
else: # if there is not probe trials, plot 2x3 subplots -> stops per trial, average stops, speed for beaconed and non-beaconed trials
fig = plt.figure(figsize = (12,12))
ax = fig.add_subplot(3,3,1) #stops per trial
ax.set_title('Beaconed trials', fontsize = 18,verticalalignment = 'bottom', style = 'italic')
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
ax.axhline(0, linewidth = 3, color = 'black') # bold line on the x axis
ax.plot(stopsdata_b[:,0],stopsdata_b[:,2], 'o', color = 'Black', markersize =4.5, label = 'Stop') #plot becaoned trials
ax.plot(reward_beac[:,0],reward_beac[:,2], '>', color = 'Red', markersize = 6, label = 'Reward') #plot becaoned trials
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0,20)
ax.set_ylim(0,trialno+0.5)
adjust_spines(ax, ['left','bottom']) # removes top and right spines
makelegend3(fig,ax)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_ylabel('Trial number', fontsize=18, labelpad = 20)
ax = fig.add_subplot(3,3,2) #stops per trial
ax.set_title('Non-beaconed trials', fontsize = 18, style = 'italic',verticalalignment = 'bottom')
ax.axvspan(8.8, 8.8+2.2, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 3, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(20-3, 20, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
ax.axhline(0, linewidth = 3, color = 'black') # bold line on the x axis
ax.plot(stopsdata_nb[:,0],stopsdata_nb[:,2], 'o',color = 'Black', markersize = 4.5) #plot becaoned trials
ax.plot(reward_nbeac[:,0],reward_nbeac[:,2], '>', color = 'Red', markersize = 6, label = 'Reward') #plot becaoned trials
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0,20)
ax.set_ylim(0,trialno+0.5)
adjust_spines(ax, ['left','bottom']) # re;moves top and right spines
makelegend3(fig,ax) # makes legend
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set xsnumber of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_yticklabels(['', '', ''])
ax = fig.add_subplot(3,3,4)
ax.axvspan(44, 44+11, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(-0.05, linewidth = 3, color = 'black')
ax.plot(bins*5, srbin_mean_b, color = 'blue',linewidth=2) #plot becaoned trials
ax.fill_between(bins*5,srbin_mean_b-srbin_std_b,srbin_mean_b+srbin_std_b, facecolor = 'blue', alpha = 0.3)
ax.plot(bins*5, shuffled_mean_b,'--' ,color = 'Black',linewidth=2) #plot becaoned trials
ax.fill_between(bins*5,shuffled_mean_b-shuffled_std_b,shuffled_mean_b+shuffled_std_b, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0, 101)
ax.set_ylim(-0.05,1.25)
adjust_spines(ax, ['left','bottom'])
ax.set_ylabel('Stops (cm/trial)', fontsize=18, labelpad = 20)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
#avg stops histogram - non beaconed
ax = fig.add_subplot(3,3,5)
ax.axvspan(44, 44+11, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(-0.05, linewidth = 3, color = 'black')
ax.plot(bins*5,srbin_mean_nb, color = 'blue',linewidth=2, label = 'Real') #plot becaoned trials
ax.fill_between(bins*5,srbin_mean_nb-srbin_std_nb,srbin_mean_nb+srbin_std_nb, facecolor = 'blue', alpha = 0.3)
ax.plot(bins*5, shuffled_mean_nb, '--',color = 'Black',linewidth=2, label = 'Shuffled') #plot becaoned trials
ax.fill_between(bins*5,shuffled_mean_nb-shuffled_std_nb,shuffled_mean_nb+shuffled_std_nb, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
adjust_spines(ax, ['left','bottom'])
ax.set_yticklabels(['', '', ''])
makelegend4(fig,ax) # makes legend
ax.set_xlim(0, 101)
ax.set_ylim(-0.05,1.25)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['', '', ''])
ax.set_yticklabels(['', '', ''])
ax = fig.add_subplot(3,3,7)
ax.axvspan(44, 44+11, facecolor='DarkGreen', alpha=0.25, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.15, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.15, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(0, linewidth = 3, color = 'black')
ax.plot(bins*5,speed_beaconed,'-',markersize = 2, color = 'Black',linewidth = 1) #plot becaoned trials
ax.fill_between(bins*5,speed_beaconed-sd_speed_beaconed,speed_beaconed+sd_speed_beaconed, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
ax.set_xlim(0, 101)
ax.set_ylim(0,120)
adjust_spines(ax, ['left','bottom'])
ax.set_ylabel('Speed (cm/s)', fontsize=18, labelpad = 20)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['-30', '100', '170'])
#avg stops histogram - non beaconed
ax = fig.add_subplot(3,3,8)
ax.axvspan(44, 44+11, facecolor='g', alpha=0.2, hatch = '/', linewidth =0) # green box spanning the rewardzone to mark reward zone
ax.axvspan(0, 15, facecolor='k', alpha=0.1, hatch = '/', linewidth =0) # black box
ax.axvspan(100-15, 100, facecolor='k', alpha=0.1, hatch = '/', linewidth =0)# black box
ax.axvline(0, linewidth = 3, color = 'black')
ax.axhline(0, linewidth = 3, color = 'black')
ax.plot(bins*5,speed_nbeaconed, '-',markersize = 2,color = 'Black',linewidth = 1) #plot becaoned trials
ax.fill_between(bins*5,speed_nbeaconed-sd_speed_nbeaconed,speed_nbeaconed+sd_speed_nbeaconed, facecolor = 'Black', alpha = 0.3)
ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8,labelsize =18)
ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 8, labelsize =18)
adjust_spines(ax, ['left','bottom'])
ax.set_yticklabels(['', '', ''])
ax.set_xlim(0, 101)
ax.set_ylim(0,120)
ax.locator_params(axis = 'x', nbins=3) # set number of ticks on x axis
ax.locator_params(axis = 'y', nbins=4) # set number of ticks on y axis
ax.set_xticklabels(['0', '100', '200'])
ax.set_xlabel('Location (cm)', fontsize=18, labelpad = 20)
ax.set_yticklabels(['', '', ''])
plt.subplots_adjust(hspace = .35, wspace = .35, bottom = 0.15, left = 0.07, right = 0.82, top = 0.92)
fig.savefig('Plots/Figure1/ExampleData/Example' + 'Data' + '_' + str(mouse) + '_' + str(day) + '.png', dpi = 200)
plt.close()
except IndexError:
print('Error')