|
67 | 67 | n_channels = len(raw.ch_names) |
68 | 68 |
|
69 | 69 | # Plot a sample of brain and stimulus activity |
70 | | -fig, ax = plt.subplots() |
| 70 | +fig, ax = plt.subplots(layout="constrained") |
71 | 71 | lns = ax.plot(scale(raw[:, :800][0].T), color="k", alpha=0.1) |
72 | 72 | ln1 = ax.plot(scale(speech[0, :800]), color="r", lw=2) |
73 | 73 | ax.legend([lns[0], ln1[0]], ["EEG", "Speech Envelope"], frameon=False) |
74 | 74 | ax.set(title="Sample activity", xlabel="Time (s)") |
75 | | -mne.viz.tight_layout() |
76 | 75 |
|
77 | 76 | # %% |
78 | 77 | # Create and fit a receptive field model |
|
117 | 116 | mean_scores = scores.mean(axis=0) |
118 | 117 |
|
119 | 118 | # Plot mean prediction scores across all channels |
120 | | -fig, ax = plt.subplots() |
| 119 | +fig, ax = plt.subplots(layout="constrained") |
121 | 120 | ix_chs = np.arange(n_channels) |
122 | 121 | ax.plot(ix_chs, mean_scores) |
123 | 122 | ax.axhline(0, ls="--", color="r") |
124 | 123 | ax.set(title="Mean prediction score", xlabel="Channel", ylabel="Score ($r$)") |
125 | | -mne.viz.tight_layout() |
126 | 124 |
|
127 | 125 | # %% |
128 | 126 | # Investigate model coefficients |
|
134 | 132 |
|
135 | 133 | # Print mean coefficients across all time delays / channels (see Fig 1) |
136 | 134 | time_plot = 0.180 # For highlighting a specific time. |
137 | | -fig, ax = plt.subplots(figsize=(4, 8)) |
| 135 | +fig, ax = plt.subplots(figsize=(4, 8), layout="constrained") |
138 | 136 | max_coef = mean_coefs.max() |
139 | 137 | ax.pcolormesh( |
140 | 138 | times, |
|
155 | 153 | xticks=np.arange(tmin, tmax + 0.2, 0.2), |
156 | 154 | ) |
157 | 155 | plt.setp(ax.get_xticklabels(), rotation=45) |
158 | | -mne.viz.tight_layout() |
159 | 156 |
|
160 | 157 | # Make a topographic map of coefficients for a given delay (see Fig 2C) |
161 | 158 | ix_plot = np.argmin(np.abs(time_plot - times)) |
162 | | -fig, ax = plt.subplots() |
| 159 | +fig, ax = plt.subplots(layout="constrained") |
163 | 160 | mne.viz.plot_topomap( |
164 | 161 | mean_coefs[:, ix_plot], pos=info, axes=ax, show=False, vlim=(-max_coef, max_coef) |
165 | 162 | ) |
166 | 163 | ax.set(title="Topomap of model coefficients\nfor delay %s" % time_plot) |
167 | | -mne.viz.tight_layout() |
168 | 164 |
|
169 | 165 | # %% |
170 | 166 | # Create and fit a stimulus reconstruction model |
|
240 | 236 |
|
241 | 237 | y_pred = sr.predict(Y[test]) |
242 | 238 | time = np.linspace(0, 2.0, 5 * int(sfreq)) |
243 | | -fig, ax = plt.subplots(figsize=(8, 4)) |
| 239 | +fig, ax = plt.subplots(figsize=(8, 4), layout="constrained") |
244 | 240 | ax.plot( |
245 | 241 | time, speech[test][sr.valid_samples_][: int(5 * sfreq)], color="grey", lw=2, ls="--" |
246 | 242 | ) |
247 | 243 | ax.plot(time, y_pred[sr.valid_samples_][: int(5 * sfreq)], color="r", lw=2) |
248 | 244 | ax.legend([lns[0], ln1[0]], ["Envelope", "Reconstruction"], frameon=False) |
249 | 245 | ax.set(title="Stimulus reconstruction") |
250 | 246 | ax.set_xlabel("Time (s)") |
251 | | -mne.viz.tight_layout() |
252 | 247 |
|
253 | 248 | # %% |
254 | 249 | # Investigate model coefficients |
|
292 | 287 | title="Inverse-transformed coefficients\nbetween delays %s and %s" |
293 | 288 | % (time_plot[0], time_plot[1]) |
294 | 289 | ) |
295 | | -mne.viz.tight_layout() |
296 | 290 |
|
297 | 291 | # %% |
298 | 292 | # References |
|
0 commit comments