-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsup_figure_1.py
270 lines (196 loc) · 8.03 KB
/
sup_figure_1.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
import numpy as np
import pandas as pd
from scipy.spatial.distance import cdist
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from plotutils import set_style, savefig
def poisson_disc_sample(array_radius, fixation_radius, radius, candidates):
"""Find positions using poisson-disc sampling."""
# See http://bost.ocks.org/mike/algorithms/
rs = np.random.RandomState(15)
uniform = rs.uniform
randint = rs.randint
# Start at a fixed point we know will work
start = 0, array_radius / 2
samples = [start]
queue = [start]
while queue:
# Pick a sample to expand from
s_idx = randint(len(queue))
s_x, s_y = queue[s_idx]
for i in xrange(candidates):
# Generate a candidate from this sample
a = uniform(0, 2 * np.pi)
r = uniform(radius, 2 * radius)
x, y = s_x + r * np.cos(a), s_y + r * np.sin(a)
# Check the three conditions to accept the candidate
in_array = np.sqrt(x ** 2 + y ** 2) < array_radius
in_ring = np.all(cdist(samples, [(x, y)]) > radius)
in_fixation = np.sqrt(x ** 2 + y ** 2) < fixation_radius
if in_array and in_ring and not in_fixation:
# Accept the candidate
samples.append((x, y))
queue.append((x, y))
break
if (i + 1) == candidates:
# We've exhausted the particular sample
queue.pop(s_idx)
# Remove first sample to give space around the fix point
samples = np.array(samples)[1:]
return samples
def plot_dots_design(f):
# --- Define the axes positions
lefts = np.linspace(.03, .41, 4)
bottoms = np.linspace(.68, .53, 4)
ratio = f.get_figwidth() / f.get_figheight()
width = .22
height = width * ratio
# --- Initialize the frames
axes = []
for left, bottom in zip(lefts, bottoms):
ax = f.add_axes([left, bottom, width, height], axisbg=".3")
ax.set(xticks=[], yticks=[], xlim=(-1, 1), ylim=(-1, 1))
for _, spine in ax.spines.items():
spine.set(linewidth=2, color="w")
axes.append(ax)
# --- Add cue frame
for ax in axes[2:]:
colors = ["w", "k", "w", ".3"]
for i, x in enumerate(np.linspace(.1, .2, 4)):
c = colors[i]
w = 2 * (1 - x)
rect = plt.Rectangle((x - 1, x - 1), w, w,
linewidth=0, facecolor=c)
ax.add_artist(rect)
# --- Add stimulus dots
rs = np.random.RandomState(0)
# Plot the dots themselves
xy = poisson_disc_sample(1.5, .15, .19, 50)
m = np.abs(xy).max(axis=1) < .73
xy = xy[m]
xx, yy = xy.T
r, g = "#ED8A45", "#00BD3B"
c = rs.choice([r, g], p=[.75, .25], size=m.sum())
ax.scatter(xx, yy, c=c, zorder=2, marker="s", s=8, linewidth=0)
# Plot arrows indicating dot motion
t = rs.uniform(0, np.pi * 2, m.sum())
t[:m.sum() // 3] = np.pi / 2
t = rs.permutation(t)
xy_d = .06 * np.c_[np.cos(t), np.sin(t)]
for xy_i, xy_d_i, c_i in zip(xy, xy_d, c):
x_i, y_i = xy_i
x_d_i, y_d_i = xy_d_i
ax.arrow(x_i, y_i, x_d_i, y_d_i, facecolor=c_i,
head_width=.03, head_length=.02, edgecolor=c_i,
overhang=.5)
# --- Add fixation point
fix_colors = ["k", "w", "w", "w"]
for ax, c in zip(axes, fix_colors):
ax.scatter(0, 0, c=c, s=15, linewidth=0, zorder=2)
# --- Add timing info
times = ["2 - 10s", ".5s", "0 or 1s", "0 or 2s"]
for time, ax in zip(times, axes):
ax.text(-.9, -1.15, time, size=8)
def plot_sticks_design(f):
# --- Define axes positions
lefts = np.linspace(.05, .36, 3)
bottoms = np.linspace(.15, .05, 3)
ratio = f.get_figwidth() / f.get_figheight()
width = .24
height = width * ratio
# --- Initialize the axes frames
axes = []
for left, bottom in zip(lefts, bottoms):
ax = f.add_axes([left, bottom, width, height], axisbg=".3")
ax.set(xticks=[], yticks=[], xlim=(-1, 1), ylim=(-1, 1))
for _, spine in ax.spines.items():
spine.set(linewidth=2, color="w")
axes.append(ax)
# --- Add the cue polygon
cue = mpl.patches.CirclePolygon((0, 0), .1, 5,
color=".5", linewidth=0)
ax.add_artist(cue)
# --- Add the stimulus
points = poisson_disc_sample(.9, .15, .1, 30)
# Define markers to show left and right tilted sticks
markers = dict(left=[(-1, 1), (1, -1)], right=[(-1, -1), (1, 1)])
# Assign colors to show red and green sticks
rgb_colors = np.array(["#A7D2A2", "#F2BB97"])
# Assign orientation and color values for each stick
rs = np.random.RandomState(0)
stick_ori = rs.choice(["left", "right"], len(points), p=[.7, .3])
stick_colors = rgb_colors[rs.choice([0, 1], len(points), p=[.7, .3])]
for ori in ["left", "right"]:
# Draw the subset of sticks with this orientation
ori_points = points[stick_ori == ori]
ax.scatter(*ori_points.T, s=8, linewidth=.75,
edgecolor=stick_colors[stick_ori == ori],
marker=markers[ori])
# --- Add the fixation point
fix_colors = ["k", "w", "w", "w"]
for ax, c in zip(axes, fix_colors):
ax.scatter(0, 0, c=c, s=15, linewidth=0, zorder=2)
# --- Add timing info
times = [".72 - 7.2s", ".72s", "< 2.88s"]
for time, ax in zip(times, axes):
ax.text(-.9, -1.15, time, size=8)
def plot_behavior(f):
# --- Set up the axes
grid = plt.GridSpec(2, 2, .71, .05, .99, .85, .5, .5)
axes = [f.add_subplot(spec) for spec in grid]
# --- Plot Experiment 1 behavior
dots_behav = pd.read_csv("data/dots_behav.csv")
sns.pointplot(x="context", y="rt", hue="subj",
ci=None, palette=[".5"], order=["motion", "color"],
data=dots_behav, ax=axes[0])
sns.pointplot(x="context", y="correct", hue="subj",
ci=None, palette=[".5"], order=["motion", "color"],
data=dots_behav, ax=axes[1])
# --- Plot Exeperiment 2 behavior
sticks_behav = pd.read_csv("data/sticks_behav.csv")
sns.pointplot(x="context", y="rt", hue="subj",
ci=None, palette=[".3"], order=["ori", "hue"],
data=sticks_behav.query("context_diff == 'easy'"),
ax=axes[2])
sns.pointplot(x="context", y="rt", hue="subj",
ci=None, palette=[".6"], order=["ori", "hue"],
data=sticks_behav.query("context_diff == 'hard'"),
ax=axes[2])
sns.pointplot(x="context", y="correct", hue="subj",
ci=None, palette=[".3"], order=["ori", "hue"],
data=sticks_behav.query("context_diff == 'easy'"),
ax=axes[3])
sns.pointplot(x="context", y="correct", hue="subj",
ci=None, palette=[".6"], order=["ori", "hue"],
data=sticks_behav.query("context_diff == 'hard'"),
ax=axes[3])
# --- Tweak axes attributes
for ax in axes[::2]:
ax.set(ylim=(.6, 1.8), yticks=np.linspace(.6, 1.8, 5))
ax.set_ylabel("Reaction time (s)", labelpad=3)
for ax in axes[1::2]:
ax.set(ylim=(.5, 1))
ax.set_ylabel("P(correct)", labelpad=1)
for ax in axes[:2]:
ax.set(xticklabels=["Motion", "Color"])
for ax in axes[2:]:
ax.set(xticklabels=["Orient", "Color"])
for ax in axes:
plt.setp(ax.collections, sizes=[5], clip_on=False)
ax.legend_ = None
ax.set(xlabel="", xlim=(-.2, 1.2))
sns.despine(ax=ax, trim=True)
if __name__ == "__main__":
set_style()
f = plt.figure(figsize=(6.5, 5))
plot_dots_design(f)
plot_sticks_design(f)
plot_behavior(f)
f.text(.5, .95, "Experiment 1", size=12, ha="center")
f.text(.5, .45, "Experiment 2", size=12, ha="center")
f.text(.01, .95, "A", size=12)
f.text(.01, .45, "B", size=12)
f.text(.64, .85, "C", size=12)
f.text(.64, .37, "D", size=12)
savefig(f, __file__)