-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotting.py
More file actions
410 lines (321 loc) · 15.8 KB
/
Copy pathPlotting.py
File metadata and controls
410 lines (321 loc) · 15.8 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
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
403
404
405
406
407
408
409
410
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 14 10:12:21 2018
@author: u1490431
"""
''' Contains code for plotting Distraction Behaviour '''
# (1) Bar scatter plots for licking
'''
MALES
which groups?
what variables?
individual data points with means
barscatter(data)
(2) data - lick day not paired. Bursts, lengths
Bursts IBIs
Runs
BY GROUP - saline and pcp (male and female )
AND
(1) percent distracted lick day, distraction, habituation, hab2, apmetamine IP
DATA FORMAT :
'''
'''
data = [all_mean_IBI_sal_M, all_mean_IBI_sal_M]
distractionData = np.empty((2,), dtype=np.object)
distractionData[0] = np.array(all_mean_IBI_sal_M)
distractionData[1] = np.array(all_mean_IBI_sal_M)
'''
# PUT ALL OF THE BURST LENGTHS IN HERE, THEN SEE AND ADD IN MEAN MEAN BURST LENGTH
meanburstlength = np.empty((2,), dtype=np.object)
meanburstlength[0] = np.array(all_mean_burst_length_sal_M)
meanburstlength[1] = np.array(all_mean_burst_length_pcp_M)
#meanburstlength[2] = np.array(all_mean_burst_length_sal_F)
#meanburstlength[3] = np.array(all_mean_burst_length_pcp_F)
meanrunlength = np.empty((2,), dtype=np.object)
meanrunlength[0] = np.array(all_mean_run_length_sal_M)
meanrunlength[1] = np.array(all_mean_run_length_pcp_M)
#meanrunlength[2] = np.array(all_mean_run_length_sal_F)
#meanrunlength[3] = np.array(all_mean_run_length_pcp_F)
nbursts = np.empty((2,), dtype=np.object)
nbursts[0] = np.array(all_n_bursts_sal_M)
nbursts[1] = np.array(all_n_bursts_pcp_M)
#nbursts[2] = np.array(all_n_bursts_sal_F)
#nbursts[3] = np.array(all_n_bursts_pcp_F)
nruns = np.empty((4,), dtype=np.object)
nruns[0] = np.array(all_n_runs_sal_M)
nruns[1] = np.array(all_n_runs_pcp_M)
#nruns[2] = np.array(all_n_runs_sal_F)
#nruns[3] = np.array(all_n_runs_pcp_F)
meanIBI = np.empty((2,), dtype=np.object)
meanIBI[0] = np.array(all_mean_IBI_sal_M)
meanIBI[1] = np.array(all_mean_IBI_pcp_M)
#meanIBI[2] = np.array(all_mean_IBI_sal_F)
#meanIBI[3] = np.array(all_mean_IBI_pcp_F)
meanIRI = np.empty((2,), dtype=np.object)
meanIRI[0] = np.array(all_mean_IRI_sal_M)
meanIRI[1] = np.array(all_mean_IRI_pcp_M)
#meanIRI[2] = np.array(all_mean_IRI_sal_F)
#meanIRI[3] = np.array(all_mean_IRI_pcp_F)
#### nRuns
a = []
a.extend(nruns[0])
a.extend(nruns[1])
b = ['sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal',\
'sal','sal','sal','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp',\
'pcp','pcp','pcp','pcp','pcp','pcp']
# Arbitrary value (not numeric is horizontal) with n values for data points
c = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']
# c = ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1']
df = pd.DataFrame()
df['nRuns'] = a
df['Group'] = b
df['Drug treatment'] = c
median_nRuns_sal_M = np.median(nruns[0])
median_nRuns_pcp_M = np.median(nruns[1])
sb.set_style("white")
fig, ax = plt.subplots(1,1)
plt.yticks()
ax = sb.violinplot(hue=df['Group'], x=df['nRuns'], y=df['Drug treatment'], bw = 0.4, palette=['dodgerblue', 'hotpink'], split=True, saturation=1, scale="width", inner=None)
ax.legend().set_visible(False)
ax.set_xlabel("doesnt change!", fontsize=14)
ax.tick_params(labelsize=14)
ax = sb.swarmplot(x=df["nRuns"], y=df["Drug treatment"], hue=df["Group"], palette=['dodgerblue', 'hotpink'], size=6)
ax.bar(median_nRuns_pcp_M,0.3, color='white') # USE THIS TO ADD IN MEAN/MEDIAN - MAKE BARS NARROW AND CLEANER
ax.bar(median_nRuns_sal_M,-0.3, color='white')
sb.despine(offset=10, trim=True)
ax.set_ylabel("")
ax.set(yticks=[])
# Choose the legend you want from the 4 options plotted
handles, labels = ax.get_legend_handles_labels()
l = plt.legend(handles[2:4], labels[2:4], fontsize=14)
# Make a gap between the distributions for easier comparison, offset determined by delta
inner=None
delta =0.05
final_width = 0.6
inner=None
offset_violinplot_halves(ax, delta, final_width, inner, 'horizontal') ## Add this function to all funcs. be careful with import names sns vs sb
#fig.savefig('/Volumes/KPMSB352/Distraction photometry paper/BehaviourFigs/nRun Violin.pdf', bbox_inches="tight")
#### nBursts
a = []
a.extend(nbursts[0])
a.extend(nbursts[1])
b = ['sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal',\
'sal','sal','sal','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp',\
'pcp','pcp','pcp','pcp','pcp','pcp']
# Arbitrary value (not numeric is horizontal) with n values for data points
c = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',]
df = pd.DataFrame()
df['nBursts'] = a
df['Group'] = b
df['Drug treatment'] = c
median_nBursts_sal_M = np.median(nbursts[0])
median_nBursts_pcp_M = np.median(nbursts[1])
sb.set_style("white")
fig, ax2 = plt.subplots(1,1)
plt.yticks()
ax2 = sb.violinplot(hue=df['Group'], x=df['nBursts'], y=df['Drug treatment'], bw = 0.4, palette=['dodgerblue', 'hotpink'], split=True, saturation=1, scale="width", inner=None)
ax2.legend().set_visible(False)
ax2.set_xlabel("doesnt change!", fontsize=14)
ax2.tick_params(labelsize=14)
ax2 = sb.swarmplot(x=df["nBursts"], y=df["Drug treatment"], hue=df["Group"], palette=['dodgerblue', 'hotpink'], size=6)
ax2.bar(median_nBursts_pcp_M,0.3, color='white') # USE THIS TO ADD IN MEAN/MEDIAN - MAKE BARS NARROW AND CLEANER
ax2.bar(median_nBursts_sal_M,-0.3, color='white')
sb.despine(offset=10, trim=True)
ax2.set_ylabel("")
ax2.set(yticks=[])
# Choose the legend you want from the 4 options plotted
handles, labels = ax.get_legend_handles_labels()
l = plt.legend(handles[2:4], labels[2:4], fontsize=14)
# Make a gap between the distributions for easier comparison, offset determined by delta
inner=None
delta =0.05
final_width = 0.6
inner=None
offset_violinplot_halves(ax2, delta, final_width, inner, 'horizontal') ## Add this function to all funcs. be careful with import names sns vs sb
#fig.savefig('/Volumes/KPMSB352/Distraction photometry paper/BehaviourFigs/nBurst Violin.pdf', bbox_inches="tight")
## Mean burst length
a = []
a.extend(meanburstlength[0])
a.extend(meanburstlength[1])
b = ['sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal',\
'sal','sal','sal','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp',\
'pcp','pcp','pcp','pcp','pcp','pcp']
# Arbitrary value (not numeric is horizontal) with n values for data points
c = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']
# c = ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1']
df = pd.DataFrame()
df['meanBurstlen'] = a
df['Group'] = b
df['Drug treatment'] = c
median_meanBurstlen_sal_M = np.median(meanburstlength[0])
median_meanBurstlen_pcp_M = np.median(meanburstlength[1])
sb.set_style("white")
fig, ax3 = plt.subplots(1,1)
plt.yticks()
ax3 = sb.violinplot(hue=df['Group'], x=df['meanBurstlen'], y=df['Drug treatment'], bw = 0.4, palette=['dodgerblue', 'hotpink'], split=True, saturation=1, scale="width", inner=None)
ax3.legend().set_visible(False)
ax3.set_xlabel("doesnt change!", fontsize=14)
ax3.tick_params(labelsize=14)
ax3 = sb.swarmplot(x=df["meanBurstlen"], y=df["Drug treatment"], hue=df["Group"], palette=['dodgerblue', 'hotpink'], size=6)
ax3.bar(median_meanBurstlen_pcp_M,0.3, color='white') # USE THIS TO ADD IN MEAN/MEDIAN - MAKE BARS NARROW AND CLEANER
ax3.bar(median_meanBurstlen_sal_M,-0.3, color='white')
sb.despine(offset=10, trim=True)
ax3.set_ylabel("")
ax3.set(yticks=[])
# Choose the legend you want from the 4 options plotted
handles, labels = ax.get_legend_handles_labels()
l = plt.legend(handles[2:4], labels[2:4], fontsize=14)
# Make a gap between the distributions for easier comparison, offset determined by delta
inner=None
delta =0.05
final_width = 0.6
inner=None
offset_violinplot_halves(ax3, delta, final_width, inner, 'horizontal') ## Add this function to all funcs. be careful with import names sns vs sb
#fig.savefig('/Volumes/KPMSB352/Distraction photometry paper/BehaviourFigs/MeanBurstLength Violin.pdf', bbox_inches="tight")
# Mean run length
a = []
a.extend(meanrunlength[0])
a.extend(meanrunlength[1])
b = ['sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal',\
'sal','sal','sal','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp',\
'pcp','pcp','pcp','pcp','pcp','pcp']
# Arbitrary value (not numeric is horizontal) with n values for data points
c = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']
# c = ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1']
df = pd.DataFrame()
df['meanRunlen'] = a
df['Group'] = b
df['Drug treatment'] = c
median_meanRunlen_sal_M = np.median(meanrunlength[0])
median_meanRunlen_pcp_M = np.median(meanrunlength[1])
sb.set_style("white")
fig, ax4 = plt.subplots(1,1)
plt.yticks()
ax4 = sb.violinplot(hue=df['Group'], x=df['meanRunlen'], y=df['Drug treatment'], bw = 0.4, palette=['dodgerblue', 'hotpink'], split=True, saturation=1, scale="width", inner=None)
ax4.legend().set_visible(False)
ax4.set_xlabel("doesnt change!", fontsize=14)
ax4.tick_params(labelsize=14)
ax4 = sb.swarmplot(x=df["meanRunlen"], y=df["Drug treatment"], hue=df["Group"], palette=['dodgerblue', 'hotpink'], size=6)
ax4.bar(median_meanRunlen_pcp_M,0.3, color='white') # USE THIS TO ADD IN MEAN/MEDIAN - MAKE BARS NARROW AND CLEANER
ax4.bar(median_meanRunlen_sal_M,-0.3, color='white')
sb.despine(offset=10, trim=True)
ax4.set_ylabel("")
ax4.set(yticks=[])
# Choose the legend you want from the 4 options plotted
handles, labels = ax.get_legend_handles_labels()
l = plt.legend(handles[2:4], labels[2:4], fontsize=14)
# Make a gap between the distributions for easier comparison, offset determined by delta
inner=None
delta =0.05
final_width = 0.6
inner=None
offset_violinplot_halves(ax4, delta, final_width, inner, 'horizontal') ## Add this function to all funcs. be careful with import names sns vs sb
#fig.savefig('/Volumes/KPMSB352/Distraction photometry paper/BehaviourFigs/MeanRunLength Violin.pdf', bbox_inches="tight")
# Mean IBI
a = []
a.extend(meanIBI[0])
a.extend(meanIBI[1])
b = ['sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal',\
'sal','sal','sal','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp',\
'pcp','pcp','pcp','pcp','pcp','pcp']
# Arbitrary value (not numeric is horizontal) with n values for data points
c = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']
# c = ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1']
df = pd.DataFrame()
df['meanIBI'] = a
df['Group'] = b
df['Drug treatment'] = c
median_IBI_sal_M = np.median(meanIBI[0])
median_IBI_pcp_M = np.median(meanIBI[1])
sb.set_style("white")
fig, ax5= plt.subplots(1,1)
plt.yticks()
ax5 = sb.violinplot(hue=df['Group'], x=df['meanIBI'], y=df['Drug treatment'], bw = 0.4, palette=['dodgerblue', 'hotpink'], split=True, saturation=1, scale="width", inner=None)
ax5.legend().set_visible(False)
ax5.set_xlabel("doesnt change!", fontsize=14)
ax5.tick_params(labelsize=14)
ax5 = sb.swarmplot(x=df["meanIBI"], y=df["Drug treatment"], hue=df["Group"], palette=['dodgerblue', 'hotpink'], size=6)
ax5.bar(median_IBI_pcp_M,0.3, color='white') # USE THIS TO ADD IN MEAN/MEDIAN - MAKE BARS NARROW AND CLEANER
ax5.bar(median_IBI_sal_M,-0.3, color='white')
sb.despine(offset=10, trim=True)
ax5.set_ylabel("")
ax5.set(yticks=[])
# Choose the legend you want from the 4 options plotted
handles, labels = ax5.get_legend_handles_labels()
l = plt.legend(handles[2:4], labels[2:4], fontsize=14)
# Make a gap between the distributions for easier comparison, offset determined by delta
inner=None
delta =0.05
final_width = 0.6
inner=None
offset_violinplot_halves(ax5, delta, final_width, inner, 'horizontal') ## Add this function to all funcs. be careful with import names sns vs sb
#fig.savefig('/Volumes/KPMSB352/Distraction photometry paper/BehaviourFigs/MeanIBI Violin.pdf', bbox_inches="tight")
# Mean IRI
a = []
a.extend(meanIRI[0])
a.extend(meanIRI[1])
b = ['sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal','sal',\
'sal','sal','sal','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp','pcp',\
'pcp','pcp','pcp','pcp','pcp','pcp']
# Arbitrary value (not numeric is horizontal) with n values for data points
c = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']
# c = ['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1']
df = pd.DataFrame()
df['meanIRI'] = a
df['Group'] = b
df['Drug treatment'] = c
median_IRI_sal_M = np.median(meanIRI[0])
median_IRI_pcp_M = np.median(meanIRI[1])
sb.set_style("white")
fig, ax6= plt.subplots(1,1)
plt.yticks()
ax6 = sb.violinplot(hue=df['Group'], x=df['meanIRI'], y=df['Drug treatment'], bw = 0.4, palette=['dodgerblue', 'hotpink'], split=True, saturation=1, scale="width", inner=None)
ax6.legend().set_visible(False)
ax6.set_xlabel("doesnt change!", fontsize=14)
ax6.tick_params(labelsize=14)
ax6 = sb.swarmplot(x=df["meanIRI"], y=df["Drug treatment"], hue=df["Group"], palette=['dodgerblue', 'hotpink'], size=6)
ax6.bar(median_IRI_pcp_M,0.3, color='white') # USE THIS TO ADD IN MEAN/MEDIAN - MAKE BARS NARROW AND CLEANER
ax6.bar(median_IRI_sal_M,-0.3, color='white')
sb.despine(offset=10, trim=True)
ax6.set_ylabel("")
ax6.set(yticks=[])
# Choose the legend you want from the 4 options plotted
handles, labels = ax6.get_legend_handles_labels()
l = plt.legend(handles[2:4], labels[2:4], fontsize=14)
# Make a gap between the distributions for easier comparison, offset determined by delta
inner=None
delta =0.05
final_width = 0.6
inner=None
offset_violinplot_halves(ax6, delta, final_width, inner, 'horizontal') ## Add this function to all funcs. be careful with import names sns vs sb
#fig.savefig('/Volumes/KPMSB352/Distraction photometry paper/BehaviourFigs/MeanIRI Violin.pdf', bbox_inches="tight")
### CODE OVERWRITES DATAFRAME EACH TIME, CANNOT ACCESS PREVIOUS VARIABLES. RRE NEEDED
##################################################################################
# Barscatter plots for grouped data. PCP vs SAL
# PLOT PERCENTAGE DISTRACTED, by modality - run ANOVA (saline vs pcp)
# PLOT percentage distracted saline vs pcp (males) (female) just distraction day
# Large plot of all days for just saline MALES
# Large plot of all days for just saline MALES
# Individual differences, linear regression for PREDP and POSTDP
# Try this plot with 16 averages one from each rat. Average pause and average pre??
# Really want individual data here not averages
# Very variable though , issues with wild outliers messing up the regression
# Maybe limit to the PDPs under 2 seconds (then same window of 1 second either way and reduced variablity)
'''
compare distracted and not distracted pdps (all together) with all pre-dps too
plot these
flatten the arrays
can go through and find if distracted or not based on the pdp
## Read in ALL of the licks?? Or bursts
### All bar scatters for percent distracted - or even violin plots
### Correlation using seaborn model - regression
## VERY few are less than 2 seconds, when they are distracted they are REALLY distracted
## Look at the pdps compare the mean or even median for distracted and not
count = 0
for trial in pdps_dis_sal_M:
for tril in trial[0]:
if tril < 10:
count += 1
# cuts out the extremes. 114 are under 10 seconds. 66 are over 10 seconds
'''