-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure7_template.py
412 lines (335 loc) · 17.3 KB
/
figure7_template.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
403
404
405
406
407
408
409
410
411
412
from reproducible_ephys_functions import (figure_style, get_row_coord, get_label_pos, plot_horizontal_institute_legend,
BRAIN_REGIONS, REGION_RENAME)
import matplotlib.pyplot as plt
import figrid as fg
region_colors = figure_style(return_colors=True)
width = 7
height = 5
fig = plt.figure(figsize=(width, height))
xspans = get_row_coord(width, [1, 5, 5, 5, 5, 5, 5], hspace=[0.5, 0.6, 0.2, 0.2, 0.2, 0.2])
xspans_labels = get_row_coord(width, [1, 5, 25], hspace=[0.5, 0.6])
yspans = get_row_coord(height, [10, 10, 10, 2], hspace=[0.5, 0.5, 0.4], pad=0.3)
axs = {
'label1': fg.place_axes_on_grid(fig, xspan=xspans[0], yspan=yspans[0]),
'label2': fg.place_axes_on_grid(fig, xspan=xspans[0], yspan=yspans[1]),
'label3': fg.place_axes_on_grid(fig, xspan=xspans[0], yspan=yspans[2]),
'regions': fg.place_axes_on_grid(fig, xspan=xspans_labels[1], yspan=yspans[3]),
'labs': fg.place_axes_on_grid(fig, xspan=xspans_labels[2], yspan=yspans[3]),
'A_1': fg.place_axes_on_grid(fig, xspan=xspans[1], yspan=yspans[0]),
'A_2': fg.place_axes_on_grid(fig, xspan=xspans[1], yspan=yspans[1]),
'A_3': fg.place_axes_on_grid(fig, xspan=xspans[1], yspan=yspans[2]),
'B_VIs_1': fg.place_axes_on_grid(fig, xspan=xspans[2], yspan=yspans[0]),
'B_VIs_2': fg.place_axes_on_grid(fig, xspan=xspans[2], yspan=yspans[1]),
'B_VIs_3': fg.place_axes_on_grid(fig, xspan=xspans[2], yspan=yspans[2]),
'B_CA1_1': fg.place_axes_on_grid(fig, xspan=xspans[3], yspan=yspans[0]),
'B_CA1_2': fg.place_axes_on_grid(fig, xspan=xspans[3], yspan=yspans[1]),
'B_CA1_3': fg.place_axes_on_grid(fig, xspan=xspans[3], yspan=yspans[2]),
'B_CA1_1': fg.place_axes_on_grid(fig, xspan=xspans[4], yspan=yspans[0]),
'B_CA1_2': fg.place_axes_on_grid(fig, xspan=xspans[4], yspan=yspans[1]),
'B_CA1_3': fg.place_axes_on_grid(fig, xspan=xspans[4], yspan=yspans[2]),
'B_LP_1': fg.place_axes_on_grid(fig, xspan=xspans[5], yspan=yspans[0]),
'B_LP_2': fg.place_axes_on_grid(fig, xspan=xspans[5], yspan=yspans[1]),
'B_LP_3': fg.place_axes_on_grid(fig, xspan=xspans[5], yspan=yspans[2]),
'B_PO_1': fg.place_axes_on_grid(fig, xspan=xspans[6], yspan=yspans[0]),
'B_PO_2': fg.place_axes_on_grid(fig, xspan=xspans[6], yspan=yspans[1]),
'B_PO_3': fg.place_axes_on_grid(fig, xspan=xspans[6], yspan=yspans[2]),
}
labels = [{'label_text': 'a', 'xpos': get_label_pos(width, xspans[1][0]),
'ypos': get_label_pos(height, yspans[0][0], pad=0.3),
'fontsize': 10, 'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'b', 'xpos': get_label_pos(width, xspans[2][0]),
'ypos': get_label_pos(height, yspans[0][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
]
fg.add_labels(fig, labels)
adjust = 0.3
fig.subplots_adjust(top=1 - adjust / height, bottom=(adjust - 0.2) / height, left=(adjust) / width,
right=1 - (adjust) / width)
axs['label1'].set_axis_off()
axs['label1'].annotate('Decoding', xy=(0, 0.5), xycoords='axes fraction', size='8', ha='right', va='center', rotation='vertical')
axs['label2'].set_axis_off()
axs['label2'].annotate('LDA colored by gt label', xy=(0, 0.5), xycoords='axes fraction', size='8', ha='right', va='center', rotation='vertical')
axs['label3'].set_axis_off()
axs['label3'].annotate('LDA colored by pred label', xy=(0, 0.5), xycoords='axes fraction', size='8', ha='right', va='center', rotation='vertical')
# Remove some axis
row2_xlims = []
row2_ylims = []
row3_xlims = []
row3_ylims = []
for key, ax in axs.items():
if key[0] != 'B':
continue
if 'B_VIs' not in key:
ax.set_ylabel('')
if key[-1] == 2:
ax.get_xlim()
axs['regions'].set_axis_off()
for i, reg in enumerate(BRAIN_REGIONS):
if i == 0:
text = axs['regions'].text(-0.3, 0.5, REGION_RENAME[reg], color=region_colors[reg], fontsize=8,
transform=axs['regions'].transAxes)
else:
text = axs['regions'].annotate(
' ' + REGION_RENAME[reg], xycoords=text, xy=(1, 0), verticalalignment="bottom",
color=region_colors[reg], fontsize=8)
axs['labs'].set_axis_off()
# Change this to the institutes you use in the analysis
institutions = ['Berkeley', 'CCU', 'CSHL (C)', 'CSHL (Z)', 'NYU', 'Princeton', 'SWC', 'UCL',
'UCLA', 'UW']
# Change this so the labs are roughly centered in the axis
offset = 0.05
plot_horizontal_institute_legend(institutions, axs['labs'], offset=offset)
fig.savefig('template.pdf')
# test to make things work
axs['A_1'].set_ylabel('Number of \npermutations')
axs['A_1'].set_xlabel('Macro F1')
axs['A_1'].set_title('Brain region (all neurons)')
axs['A_2'].set_ylabel('Dim2')
axs['A_2'].set_xlabel('Dim1')
fig.savefig('template.pdf')
# Figure 7 take 2
from reproducible_ephys_functions import (figure_style, get_row_coord, get_label_pos, plot_horizontal_institute_legend,
BRAIN_REGIONS, REGION_RENAME)
import matplotlib.pyplot as plt
import figrid as fg
region_colors = figure_style(return_colors=True)
width = 7
height = 6
fig = plt.figure(figsize=(width, height))
xspans1 = get_row_coord(width, [5, 1, 5, 1])
xspans2 = get_row_coord(width, [1, 1, 1, 1, 1])
yspans = get_row_coord(height, [1, 1, 1, 1], hspace=0.6, pad=0.3)
axs = {
'regions': fg.place_axes_on_grid(fig, xspan=xspans1[1], yspan=yspans[1]),
'labs': fg.place_axes_on_grid(fig, xspan=xspans1[3], yspan=yspans[1]),
'A_1': fg.place_axes_on_grid(fig, xspan=xspans1[0], yspan=yspans[0]),
'A_2': fg.place_axes_on_grid(fig, xspan=xspans1[0], yspan=yspans[1]),
'A_3': fg.place_axes_on_grid(fig, xspan=xspans1[2], yspan=yspans[0]),
'A_4': fg.place_axes_on_grid(fig, xspan=xspans1[2], yspan=yspans[1]),
'B_VIs_1': fg.place_axes_on_grid(fig, xspan=xspans2[0], yspan=yspans[2]),
'B_VIs_2': fg.place_axes_on_grid(fig, xspan=xspans2[0], yspan=yspans[3]),
'B_CA1_1': fg.place_axes_on_grid(fig, xspan=xspans2[1], yspan=yspans[2]),
'B_CA1_2': fg.place_axes_on_grid(fig, xspan=xspans2[1], yspan=yspans[3]),
'B_CA1_1': fg.place_axes_on_grid(fig, xspan=xspans2[2], yspan=yspans[2]),
'B_CA1_2': fg.place_axes_on_grid(fig, xspan=xspans2[2], yspan=yspans[3]),
'B_LP_1': fg.place_axes_on_grid(fig, xspan=xspans2[3], yspan=yspans[2]),
'B_LP_2': fg.place_axes_on_grid(fig, xspan=xspans2[3], yspan=yspans[3]),
'B_PO_1': fg.place_axes_on_grid(fig, xspan=xspans2[4], yspan=yspans[2]),
'B_PO_2': fg.place_axes_on_grid(fig, xspan=xspans2[4], yspan=yspans[3]),
}
labels = [{'label_text': 'a', 'xpos': get_label_pos(width, xspans1[0][0]),
'ypos': get_label_pos(height, yspans[0][0], pad=0.3),
'fontsize': 10, 'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'b', 'xpos': get_label_pos(width, xspans1[2][0]),
'ypos': get_label_pos(height, yspans[0][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'c', 'xpos': get_label_pos(width, xspans2[0][0]),
'ypos': get_label_pos(height, yspans[2][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
]
fg.add_labels(fig, labels)
adjust = 0.3
fig.subplots_adjust(top=1 - adjust / height, bottom=(adjust - 0.2) / height, left=(adjust) / width,
right=1 - (adjust) / width)
axs['label1'].set_axis_off()
axs['label1'].annotate('Decoding', xy=(0, 0.5), xycoords='axes fraction', size='8', ha='right', va='center', rotation='vertical')
axs['label2'].set_axis_off()
axs['label2'].annotate('LDA colored by gt label', xy=(0, 0.5), xycoords='axes fraction', size='8', ha='right', va='center', rotation='vertical')
axs['label3'].set_axis_off()
axs['label3'].annotate('LDA colored by pred label', xy=(0, 0.5), xycoords='axes fraction', size='8', ha='right', va='center', rotation='vertical')
# Remove some axis
row2_xlims = []
row2_ylims = []
row3_xlims = []
row3_ylims = []
for key, ax in axs.items():
if key[0] != 'B':
continue
if 'B_VIs' not in key:
ax.set_ylabel('')
if key[-1] == 2:
ax.get_xlim()
axs['regions'].set_axis_off()
for i, reg in enumerate(BRAIN_REGIONS):
if i == 0:
text = axs['regions'].text(-0.3, 0.5, REGION_RENAME[reg], color=region_colors[reg], fontsize=8,
transform=axs['regions'].transAxes)
else:
text = axs['regions'].annotate(
' ' + REGION_RENAME[reg], xycoords=text, xy=(1, 0), verticalalignment="bottom",
color=region_colors[reg], fontsize=8)
axs['labs'].set_axis_off()
# Change this to the institutes you use in the analysis
institutions = ['Berkeley', 'CCU', 'CSHL (C)', 'CSHL (Z)', 'NYU', 'Princeton', 'SWC', 'UCL',
'UCLA', 'UW']
# Change this so the labs are roughly centered in the axis
offset = 0.05
plot_horizontal_institute_legend(institutions, axs['labs'], offset=offset)
fig.savefig('template.pdf')
# test to make things work
axs['A_1'].set_ylabel('Number of \npermutations')
axs['A_1'].set_xlabel('Macro F1')
axs['A_1'].set_title('Brain region (all neurons)')
axs['A_2'].set_ylabel('Dim2')
axs['A_2'].set_xlabel('Dim1')
fig.savefig('template.pdf')
### FIGURE (
from reproducible_ephys_functions import (figure_style, get_row_coord, get_label_pos, plot_vertical_institute_legend,
BRAIN_REGIONS, REGION_RENAME)
import matplotlib.pyplot as plt
import figrid as fg
import numpy as np
region_colors = figure_style(return_colors=True)
width = 7
height = 7.3
fig = plt.figure(figsize=(width, height))
xspans = get_row_coord(width, [10, 1], hspace=0.2)
yspans = get_row_coord(height, [3, 2], hspace=0.8, pad=0.3)
axs = {
'A': fg.place_axes_on_grid(fig, xspan=xspans[0], yspan=yspans[0], dim=[1, 5], wspace=0.3),
'B': fg.place_axes_on_grid(fig, xspan=xspans[0], yspan=yspans[1], dim=[2, 5], wspace=0.3),
'labs_a': fg.place_axes_on_grid(fig, xspan=xspans[1], yspan=yspans[0]),
'regs_labs_b': fg.place_axes_on_grid(fig, xspan=xspans[1], yspan=yspans[1]),
}
labels = [{'label_text': 'a', 'xpos': get_label_pos(width, xspans[0][0]),
'ypos': get_label_pos(height, yspans[0][0], pad=0.3),
'fontsize': 10, 'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'b', 'xpos': get_label_pos(width, xspans[0][0]),
'ypos': get_label_pos(height, yspans[1][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
]
fg.add_labels(fig, labels)
adjust = 0.3
fig.subplots_adjust(top=1 - adjust / height, bottom=(adjust + 0.2) / height, left=(adjust + 0.2) / width,
right=1 - (adjust - 0.2) / width)
axs['labs_a'].set_axis_off()
institutions = ['Berkeley', 'CCU', 'CSHL (C)', 'CSHL (Z)', 'NYU', 'Princeton', 'SWC', 'UCL',
'UCLA', 'UW']
plot_vertical_institute_legend(institutions, axs['labs_a'], span=(0.3, 0.7), offset=0)
axs['regs_labs_b'].set_axis_off()
# plot the regions
pos = np.linspace(0.7, 0.9, len(BRAIN_REGIONS))[::-1]
for p, reg in zip(pos, BRAIN_REGIONS):
axs['regs_labs_b'].text(0, p, REGION_RENAME[reg], color=region_colors[reg], fontsize=7, transform=axs['regs_labs_b'].transAxes)
# plot the labs
institutions = ['Berkeley', 'CCU', 'CSHL (C)', 'CSHL (Z)', 'NYU', 'Princeton', 'SWC', 'UCL',
'UCLA', 'UW']
plot_vertical_institute_legend(institutions, axs['regs_labs_b'], span=(0, 0.4), offset=0)
# Hyun figure 7
figure_style()
width = 7
height = 8.74
fig = plt.figure(figsize=(width, height))
xspans_row1 = get_row_coord(width, [1])
xspans_row2 = get_row_coord(width, [1, 1])
xspans_row3 = get_row_coord(width, [2, 3])
xspans_e = get_row_coord(width, [5, 1], hspace=0.1, pad=0, span=xspans_row3[1])
yspans = get_row_coord(height, [1.5, 1.5, 1], hspace=0.8, pad=0.3)
axs = {
'A': fg.place_axes_on_grid(fig, xspan=xspans_row1[0], yspan=yspans[0]),
'B': fg.place_axes_on_grid(fig, xspan=xspans_row2[0], yspan=yspans[1], dim=[3, 1], hspace=0.3),
'C': fg.place_axes_on_grid(fig, xspan=xspans_row2[1], yspan=yspans[1], dim=[3, 2], hspace=0.4),
'D': fg.place_axes_on_grid(fig, xspan=xspans_row3[0], yspan=yspans[2]),
'E_1': fg.place_axes_on_grid(fig, xspan=xspans_e[0], yspan=yspans[2]),
'E_2': fg.place_axes_on_grid(fig, xspan=xspans_e[1], yspan=yspans[2]),
}
labels = [{'label_text': 'a', 'xpos': get_label_pos(width, xspans_row1[0][0]),
'ypos': get_label_pos(height, yspans[0][0], pad=0.3),
'fontsize': 10, 'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'b', 'xpos': get_label_pos(width, xspans_row2[0][0]),
'ypos': get_label_pos(height, yspans[1][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'c', 'xpos': get_label_pos(width, xspans_row2[1][0]),
'ypos': get_label_pos(height, yspans[1][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'd', 'xpos': get_label_pos(width, xspans_row3[0][0]),
'ypos': get_label_pos(height, yspans[2][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
{'label_text': 'e', 'xpos': get_label_pos(width, xspans_row3[1][0]),
'ypos': get_label_pos(height, yspans[2][0], pad=0.3), 'fontsize': 10,
'weight': 'bold', 'ha': 'right', 'va': 'bottom'},
]
fg.add_labels(fig, labels)
axs['A'].set_axis_off()
axs['B'][0].set_ylim(0, 120)
axs['B'][0].set_ylabel('Firing rate (Hz)')
axs['B'][0].set_xlim(-0.5, 1)
axs['B'][0].set_xticks([-0.5, 0, 0.5, 1])
axs['B'][0].set_xticklabels([])
axs['B'][0].set_title('Left stimulus')
axs['B'][0].plot([-0.3, 0.7], [50, 50], 'k', label='Observed')
axs['B'][0].plot([-0.3, 0.7], [50, 50], 'r', label='Predicted')
axs['B'][0].legend(loc='upper left', fontsize=6, frameon=False)
axs['B'][1].annotate('Observed \n raster plot', xy=(-0.105, 0.5), xycoords='axes fraction',
size='8', ha='right', va='center', rotation='vertical')
axs['B'][1].set_ylabel('Trials')
axs['B'][1].set_yticks([])
axs['B'][1].set_yticklabels([])
axs['B'][1].set_xlim(-0.5, 1)
axs['B'][1].set_xticks([-0.5, 0, 0.5, 1])
axs['B'][1].set_xticklabels([])
axs['B'][2].annotate('Predicted \n raster plot', xy=(-0.105, 0.5), xycoords='axes fraction',
size='8', ha='right', va='center', rotation='vertical')
axs['B'][2].set_ylabel('Trials')
axs['B'][2].set_yticks([])
axs['B'][2].set_yticklabels([])
axs['B'][2].set_xlim(-0.5, 1)
axs['B'][2].set_xticks([-0.5, 0, 0.5, 1])
axs['B'][2].set_xticklabels([-0.5, 0, 0.5, 1])
axs['B'][2].set_xlabel('Time (s)')
# im = axs['B'][2].imshow(200 * np.random.random((20, 20)), extent=[0, 0.5, 20, 40], aspect='auto', cmap='binary')
# from mpl_toolkits.axes_grid1 import make_axes_locatable
# divider = make_axes_locatable(axs['B'][2])
# colorbar_axes = divider.append_axes("right", size="100%", pad=0.1)
# cbar = fig.colorbar(im, cax=colorbar_axes, orientation='vertical')
#plt.colorbar(mappable=im, ax=axs['B'][2])
titles = ['Firing rate', 'Wheel velocity', 'Motion energy', 'Right paw speed', 'Nose tip speed', 'Licks']
for i, ax in enumerate(np.array(axs['C']).flatten()):
ax.set_yticks([])
ax.set_yticklabels([])
ax.set_xlim(-0.5, 1)
ax.set_xticks([-0.5, 0, 0.5, 1])
ax.set_title(titles[i])
if np.mod(i, 2) == 0:
ax.set_ylabel('Trials')
if i > 3:
ax.set_xlabel('Time (s)')
else:
ax.set_xticklabels([])
dlabels = ['', 'Motion energy', 'Paw speed', 'Wheel velocity', 'Lick',
'First movement', 'Stimuli', 'Go cue', 'Pupil diameter',
'Nose speed', 'Reward', 'Choice', 'Mouse prior', 'Decision strategy',
'Last mouse prior', 'Noise', '']
elabels1 = ['', 'Motion energy', 'Lick', 'Paw speed', 'Decision strategy',
'Reward', 'Brain region', 'Waveform amplitude', 'First movement',
'Nose speed', 'Mouse prior', 'Choice', 'Wheel velocity',
'Last mouse prior', 'Stimuli', 'Session', 'Pupil diameter', 'z',
'Go cue', 'x', 'y', 'Lab', 'Waveform width', 'Noise', '']
elabels2 = ['','Behavioral', 'Electrophysiological', 'Task-related', '']
axs['D'].set_xticks(np.arange(0, len(dlabels)))
axs['D'].set_xticklabels(dlabels, rotation=45, ha='right')
axs['D'].set_ylim(-0.2, 0.5)
axs['D'].set_ylabel('R$^2$')
axs['D'].set_title('Single-covariate analysis')
axs['E_1'].set_xticks(np.arange(0, len(elabels1)))
axs['E_1'].set_xticklabels(elabels1, rotation=45, ha='right')
axs['E_1'].set_ylim(-0.2, 0.5)
axs['E_1'].set_ylabel(r'$\Delta$R$^2$')
axs['E_1'].set_title('Leave-one-out analysis')
region_colors = {'LP': 'k', 'CA1': 'b', 'DG': 'r', 'PPC': 'g', 'PO': 'y'}
for i, reg in enumerate(BRAIN_REGIONS):
if i == 0:
text = axs['E_1'].text(0.5, 0.8, REGION_RENAME[reg], color=region_colors[reg], fontsize=8,
transform=axs['E_1'].transAxes)
else:
text = axs['E_1'].annotate(
' ' + REGION_RENAME[reg], xycoords=text, xy=(1, 0), verticalalignment="bottom",
color=region_colors[reg], fontsize=8)
axs['E_2'].set_xticks(np.arange(0, len(elabels2)))
axs['E_2'].set_xticklabels(elabels2, rotation=45, ha='right')
axs['E_2'].set_ylim(-0.2, 0.5)
axs['E_2'].set_yticklabels([])
axs['E_2'].set_title('Leave-group-out')
adjust = 0.3
fig.subplots_adjust(top=1 - adjust / height, bottom=(adjust + 0.4) / height, left=(adjust + 0.2) / width,
right=1 - (adjust) / width)