Skip to content

Commit 2c5e1de

Browse files
committed
ENH add explainable variance plot for two voxels
1 parent b2661fe commit 2c5e1de

2 files changed

Lines changed: 65 additions & 5 deletions

File tree

tutorials/movies_3T/01_plot_explainable_variance.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,34 @@
5757
print("(n_voxels,) =", ev.shape)
5858

5959
###############################################################################
60-
# We can plot the distribution of explainable variance over voxels.
60+
# To better understand the explainable variance, we can plot the time-courses
61+
# of a voxel with large explainable variance...
6162

6263
import matplotlib.pyplot as plt
6364

65+
voxel_1 = np.argmax(ev)
66+
plt.figure(figsize=(10, 4))
67+
plt.plot(Y_test[:, :, voxel_1].T, color='C0', alpha=0.5)
68+
plt.plot(Y_test[:, :, voxel_1].mean(0), color='C1', label='average')
69+
plt.xlabel("Time points")
70+
plt.title("Voxel with large explainable variance (%.2f)" % ev[voxel_1])
71+
plt.legend()
72+
plt.show()
73+
74+
###############################################################################
75+
# ... and of a voxel with low explainable variance.
76+
voxel_2 = np.argmin(ev)
77+
plt.figure(figsize=(10, 4))
78+
plt.plot(Y_test[:, :, voxel_2].T, color='C0', alpha=0.5)
79+
plt.plot(Y_test[:, :, voxel_2].mean(0), color='C1', label='average')
80+
plt.xlabel("Time points")
81+
plt.title("Voxel with low explainable variance (%.2f)" % ev[voxel_2])
82+
plt.legend()
83+
plt.show()
84+
85+
###############################################################################
86+
# We can also plot the distribution of explainable variance over voxels.
87+
6488
plt.hist(ev, bins=np.linspace(0, 1, 100), log=True, histtype='step')
6589
plt.xlabel("Explainable variance")
6690
plt.ylabel("Number of voxels")
@@ -133,7 +157,7 @@
133157

134158
import cortex
135159

136-
surface = "fsaverage_pycortex" # ("fsaverage" outside the Gallant lab)
160+
surface = "fsaverage"
137161

138162
if not hasattr(cortex.db, surface):
139163
cortex.utils.download_subject(subject_id=surface)

tutorials/notebooks/movies_3T/01_plot_explainable_variance.ipynb

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"cell_type": "markdown",
117117
"metadata": {},
118118
"source": [
119-
"We can plot the distribution of explainable variance over voxels.\n\n"
119+
"To better understand the explainable variance, we can plot the time-courses\nof a voxel with large explainable variance...\n\n"
120120
]
121121
},
122122
{
@@ -127,7 +127,43 @@
127127
},
128128
"outputs": [],
129129
"source": [
130-
"import matplotlib.pyplot as plt\n\nplt.hist(ev, bins=np.linspace(0, 1, 100), log=True, histtype='step')\nplt.xlabel(\"Explainable variance\")\nplt.ylabel(\"Number of voxels\")\nplt.title('Histogram of explainable variance')\nplt.grid('on')\nplt.show()"
130+
"import matplotlib.pyplot as plt\n\nvoxel_1 = np.argmax(ev)\nplt.figure(figsize=(10, 4))\nplt.plot(Y_test[:, :, voxel_1].T, color='C0', alpha=0.5)\nplt.plot(Y_test[:, :, voxel_1].mean(0), color='C1', label='average')\nplt.xlabel(\"Time points\")\nplt.title(\"Voxel with large explainable variance (%.2f)\" % ev[voxel_1])\nplt.legend()\nplt.show()"
131+
]
132+
},
133+
{
134+
"cell_type": "markdown",
135+
"metadata": {},
136+
"source": [
137+
"... and of a voxel with low explainable variance.\n\n"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {
144+
"collapsed": false
145+
},
146+
"outputs": [],
147+
"source": [
148+
"voxel_2 = np.argmin(ev)\nplt.figure(figsize=(10, 4))\nplt.plot(Y_test[:, :, voxel_2].T, color='C0', alpha=0.5)\nplt.plot(Y_test[:, :, voxel_2].mean(0), color='C1', label='average')\nplt.xlabel(\"Time points\")\nplt.title(\"Voxel with low explainable variance (%.2f)\" % ev[voxel_2])\nplt.legend()\nplt.show()"
149+
]
150+
},
151+
{
152+
"cell_type": "markdown",
153+
"metadata": {},
154+
"source": [
155+
"We can also plot the distribution of explainable variance over voxels.\n\n"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": null,
161+
"metadata": {
162+
"collapsed": false
163+
},
164+
"outputs": [],
165+
"source": [
166+
"plt.hist(ev, bins=np.linspace(0, 1, 100), log=True, histtype='step')\nplt.xlabel(\"Explainable variance\")\nplt.ylabel(\"Number of voxels\")\nplt.title('Histogram of explainable variance')\nplt.grid('on')\nplt.show()"
131167
]
132168
},
133169
{
@@ -184,7 +220,7 @@
184220
},
185221
"outputs": [],
186222
"source": [
187-
"import cortex\n\nsurface = \"fsaverage_pycortex\" # (\"fsaverage\" outside the Gallant lab)\n\nif not hasattr(cortex.db, surface):\n cortex.utils.download_subject(subject_id=surface)"
223+
"import cortex\n\nsurface = \"fsaverage\"\n\nif not hasattr(cortex.db, surface):\n cortex.utils.download_subject(subject_id=surface)"
188224
]
189225
},
190226
{

0 commit comments

Comments
 (0)