-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfig_method_diagram.py
More file actions
44 lines (38 loc) · 1.68 KB
/
fig_method_diagram.py
File metadata and controls
44 lines (38 loc) · 1.68 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
# Figure 2: coding and decoding
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.collections import PolyCollection
import numpy as np
import os
if __name__ == '__main__':
figName = 'receptive_ field_shape'
figFolder = os.path.join(os.path.dirname(__file__), 'data', 'method')
if not os.path.exists(figFolder):
os.makedirs(figFolder)
# define
fontsize = 25
prf = np.linspace(0, 2 * np.pi, 100, endpoint=True)
# receptive field with different k
fig = plt.figure(figsize=(10, 6))
ax2 = fig.add_subplot(111, polar=True)
ks = [0.1, 0.5, 1, 2, 4, 10, 50, 100]
theta = np.pi/2
# colors = ["blue", "red", "black"]
# cmap = LinearSegmentedColormap.from_list("custom_blue_red_black", colors, N=len(ks))
for (i, k) in enumerate(ks):
# color_value = cmap(i / len(ks))
color_value = plt.cm.viridis(i / len(ks))
f_F = np.exp(k * np.cos(prf - theta))
f_F = (f_F-np.min(f_F))/(np.max(f_F)-np.min(f_F))
ax2.plot(prf, f_F, label=f'$\kappa$={k}', linewidth=2, color=color_value)
ax2.set_ylim(0, 1.1)
ax2.set_yticklabels([])
angle = np.arange(0, 360, 45) * np.pi / 180
angle_degree = np.linspace(0, 360, 8, endpoint=False, dtype=int)
ax2.set_xticks(angle)
ax2.set_xticklabels([f'{theta}°' for theta in angle_degree], fontsize=fontsize, fontweight='bold')
plt.subplots_adjust(left=0.35, right=0.95, top=0.9, bottom=0.1)
ax2.legend(fontsize=fontsize, bbox_to_anchor=(-0.7, 0.15), ncol=1, loc='lower left', framealpha=0.5)
figType = ['.png', '.eps']
for ft in figType:
plt.savefig(os.path.join(figFolder, figName + ft), dpi=600)