Skip to content

Commit

Permalink
dev docs nilearn/nilearn@7ce39ab : [ENH] update default colors (#4959)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 30, 2024
1 parent c9db937 commit 498e08f
Show file tree
Hide file tree
Showing 1,133 changed files with 7,597 additions and 8,131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ def plot_slices(data, title=None):
# References
# ----------
#
# .. footbibliography::
# .. footbibliography::
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Load Haxby dataset\n\n"
"## Load Haxby dataset\n\n"
]
},
{
Expand All @@ -29,7 +29,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Restrict to faces and houses\n\n"
"## Restrict to faces and houses\n\n"
]
},
{
Expand All @@ -47,7 +47,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Mask data\n\n"
"## Mask data\n\n"
]
},
{
Expand All @@ -65,7 +65,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Perform massively univariate analysis with permuted OLS\n\nWe use a two-sided t-test to compute p-values, but we keep trace of the\neffect sign to add it back at the end and thus observe the signed effect\n\n"
"## Perform massively univariate analysis with permuted OLS\n\nWe use a two-sided t-test to compute p-values, but we keep trace of the\neffect sign to add it back at the end and thus observe the signed effect\n\n"
]
},
{
Expand Down Expand Up @@ -101,7 +101,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualization\n\n"
"## Visualization\n\n"
]
},
{
Expand All @@ -112,14 +112,14 @@
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nfrom nilearn.image import get_data\n\n# Use the fMRI mean image as a surrogate of anatomical data\nmean_fmri_img = image.mean_img(func_filename, copy_header=True)\n\nthreshold = -np.log10(0.1) # 10% corrected\n\nvmax = min(signed_neg_log_pvals.max(), neg_log_pvals_bonferroni.max())\n\n# Plot thresholded p-values map corresponding to F-scores\ndisplay = plot_stat_map(\n neg_log_pvals_bonferroni_unmasked,\n mean_fmri_img,\n threshold=threshold,\n cmap=plt.cm.RdBu_r,\n display_mode=\"z\",\n cut_coords=[-1],\n vmax=vmax,\n)\n\nneg_log_pvals_bonferroni_data = get_data(neg_log_pvals_bonferroni_unmasked)\nn_detections = (neg_log_pvals_bonferroni_data > threshold).sum()\ntitle = (\n \"Negative $\\\\log_{10}$ p-values\"\n \"\\n(Parametric two-sided F-test\"\n \"\\n+ Bonferroni correction)\"\n f\"\\n{n_detections} detections\"\n)\n\ndisplay.title(title, size=10)\n\n# Plot permutation p-values map\ndisplay = plot_stat_map(\n signed_neg_log_pvals_unmasked,\n mean_fmri_img,\n threshold=threshold,\n cmap=plt.cm.RdBu_r,\n display_mode=\"z\",\n cut_coords=[-1],\n vmax=vmax,\n)\n\nn_detections = (np.abs(signed_neg_log_pvals) > threshold).sum()\ntitle = (\n \"Negative $\\\\log_{10}$ p-values\"\n \"\\n(Non-parametric two-sided test\"\n \"\\n+ max-type correction)\"\n f\"\\n{n_detections} detections\"\n)\n\ndisplay.title(title, size=10)\n\nshow()"
"from nilearn.image import get_data\n\n# Use the fMRI mean image as a surrogate of anatomical data\nmean_fmri_img = image.mean_img(func_filename, copy_header=True)\n\nthreshold = -np.log10(0.1) # 10% corrected\n\nvmax = min(signed_neg_log_pvals.max(), neg_log_pvals_bonferroni.max())\n\n# Plot thresholded p-values map corresponding to F-scores\n\nneg_log_pvals_bonferroni_data = get_data(neg_log_pvals_bonferroni_unmasked)\nn_detections = (neg_log_pvals_bonferroni_data > threshold).sum()\ntitle = (\n \"Negative $\\\\log_{10}$ p-values\"\n \"\\n(Parametric two-sided F-test\"\n \"\\n+ Bonferroni correction)\"\n f\"\\n{n_detections} detections\"\n)\n\ndisplay = plot_stat_map(\n neg_log_pvals_bonferroni_unmasked,\n mean_fmri_img,\n threshold=threshold,\n display_mode=\"z\",\n cut_coords=[-1],\n vmax=vmax,\n vmin=threshold,\n cmap=\"inferno\",\n)\n\ndisplay.title(title, size=10)\n\n# Plot permutation p-values map\nn_detections = (np.abs(signed_neg_log_pvals) > threshold).sum()\ntitle = (\n \"Negative $\\\\log_{10}$ p-values\"\n \"\\n(Non-parametric two-sided test\"\n \"\\n+ max-type correction)\"\n f\"\\n{n_detections} detections\"\n)\n\ndisplay = plot_stat_map(\n signed_neg_log_pvals_unmasked,\n mean_fmri_img,\n threshold=threshold,\n display_mode=\"z\",\n cut_coords=[-1],\n vmax=vmax,\n vmin=threshold,\n cmap=\"inferno\",\n)\n\ndisplay.title(title, size=10)\n\nshow()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## References\n\n .. footbibliography::\n\n"
"## References\n\n.. footbibliography::\n\n"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
},
"outputs": [],
"source": [
"plot_stat_map(\n fmri_glm.r_square[0],\n bg_img=mean_img,\n threshold=0.1,\n display_mode=\"z\",\n cut_coords=7,\n cmap=\"black_red\",\n title=\"R-squared\",\n vmin=0,\n symmetric_cbar=False,\n)"
"plot_stat_map(\n fmri_glm.r_square[0],\n bg_img=mean_img,\n threshold=0.1,\n display_mode=\"z\",\n cut_coords=7,\n cmap=\"inferno\",\n title=\"R-squared\",\n vmin=0,\n symmetric_cbar=False,\n)"
]
},
{
Expand All @@ -166,7 +166,7 @@
},
"outputs": [],
"source": [
"# f-test for 'listening'\nz_map_ftest = fmri_glm.compute_contrast(\n \"listening\", stat_type=\"F\", output_type=\"z_score\"\n)\n\nplot_stat_map(\n z_map_ftest,\n bg_img=mean_img,\n threshold=threshold,\n display_mode=\"z\",\n cut_coords=7,\n cmap=\"black_red\",\n title=f\"listening > rest (F-test; Z>{threshold})\",\n symmetric_cbar=False,\n vmin=0,\n)\n\nshow()"
"# f-test for 'listening'\nz_map_ftest = fmri_glm.compute_contrast(\n \"listening\", stat_type=\"F\", output_type=\"z_score\"\n)\n\nplot_stat_map(\n z_map_ftest,\n bg_img=mean_img,\n threshold=threshold,\n display_mode=\"z\",\n cut_coords=7,\n cmap=\"inferno\",\n title=f\"listening > rest (F-test; Z>{threshold})\",\n symmetric_cbar=False,\n vmin=0,\n)\n\nshow()"
]
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified dev/_downloads/07bd43f5f35abcb693398fbe82adc61d/plot_oasis_vbm.zip
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
},
"outputs": [],
"source": [
"from sklearn.metrics import confusion_matrix\n\nsvc_ovo.fit(X[run < 10], y[run < 10])\ny_pred_ovo = svc_ovo.predict(X[run >= 10])\n\nplot_matrix(\n confusion_matrix(y_pred_ovo, y[run >= 10]),\n labels=unique_conditions,\n title=\"Confusion matrix: One vs One\",\n cmap=\"hot_r\",\n)\n\nsvc_ova.fit(X[run < 10], y[run < 10])\ny_pred_ova = svc_ova.predict(X[run >= 10])\n\nplot_matrix(\n confusion_matrix(y_pred_ova, y[run >= 10]),\n labels=unique_conditions,\n title=\"Confusion matrix: One vs All\",\n cmap=\"hot_r\",\n)\n\nshow()"
"from sklearn.metrics import confusion_matrix\n\nsvc_ovo.fit(X[run < 10], y[run < 10])\ny_pred_ovo = svc_ovo.predict(X[run >= 10])\n\nplot_matrix(\n confusion_matrix(y_pred_ovo, y[run >= 10]),\n labels=unique_conditions,\n title=\"Confusion matrix: One vs One\",\n cmap=\"inferno\",\n)\n\nsvc_ova.fit(X[run < 10], y[run < 10])\ny_pred_ova = svc_ova.predict(X[run >= 10])\n\nplot_matrix(\n confusion_matrix(y_pred_ova, y[run >= 10]),\n labels=unique_conditions,\n title=\"Confusion matrix: One vs All\",\n cmap=\"inferno\",\n)\n\nshow()"
]
}
],
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
#
# The file contains a 3D volume, we can easily visualize it as a
# statistical map:
from nilearn import plotting
from nilearn.plotting import plot_stat_map, show

plotting.plot_stat_map(tmap_filename)
plot_stat_map(tmap_filename)

# %%
# Visualizing works better with a threshold
plotting.plot_stat_map(tmap_filename, threshold=3)
plot_stat_map(tmap_filename, threshold=3)


# %%
Expand Down Expand Up @@ -67,7 +67,7 @@
# first_rsn is a 3D image.
#
# We can then plot it
plotting.plot_stat_map(first_rsn)
plot_stat_map(first_rsn)


# %%
Expand All @@ -81,7 +81,7 @@
# compact display.
for img in image.iter_img(rsn):
# img is now an in-memory 3D img
plotting.plot_stat_map(
plot_stat_map(
img, threshold=3, display_mode="z", cut_coords=1, colorbar=False
)

Expand All @@ -103,13 +103,13 @@
# to the previous plot above.

for img in image.iter_img(selected_volumes):
plotting.plot_stat_map(img)
plot_stat_map(img)


# %%
# plotting.show is useful to force the display of figures when running
# outside IPython
plotting.show()
show()

# %%
# |
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## References\n\n .. footbibliography::\n\n"
"## References\n\n.. footbibliography::\n\n"
]
}
],
Expand Down
30 changes: 16 additions & 14 deletions dev/_downloads/1762b321e2d54728de2d7ecfc8d506f2/plot_oasis_vbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from nilearn.image import get_data
from nilearn.maskers import NiftiMasker

n_subjects = 100 # more subjects requires more memory
n_subjects = 200 # more subjects requires more memory

# %%
# Load Oasis dataset
Expand Down Expand Up @@ -154,9 +154,13 @@
bg_filename = gray_matter_map_filenames[0]
z_slice = 0
display = plot_stat_map(
weight_img, bg_img=bg_filename, display_mode="z", cut_coords=[z_slice]
weight_img,
bg_img=bg_filename,
display_mode="z",
cut_coords=[z_slice],
title="SVM weights",
cmap="cold_hot",
)
display.title("SVM weights")
show()

# %%
Expand Down Expand Up @@ -206,24 +210,22 @@
# Show results
threshold = -np.log10(0.1) # 10% corrected

fig = plt.figure(figsize=(5.5, 7.5), facecolor="k")
n_detections = (get_data(signed_neg_log_pvals_unmasked) > threshold).sum()

display = plot_stat_map(
title = (
"Negative $\\log_{10}$ p-values\n(Non-parametric + max-type correction)"
f"\n{int(n_detections)} detections"
)

plot_stat_map(
signed_neg_log_pvals_unmasked,
bg_img=bg_filename,
threshold=threshold,
cmap=plt.cm.RdBu_r,
display_mode="z",
cut_coords=[z_slice],
figure=fig,
figure=plt.figure(figsize=(5.5, 7.5), facecolor="k"),
title=title,
)
title = (
"Negative $\\log_{10}$ p-values\n(Non-parametric + max-type correction)"
)
display.title(title)

n_detections = (get_data(signed_neg_log_pvals_unmasked) > threshold).sum()
print(f"\n{int(n_detections)} detections")

show()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
The :func:`~nilearn.plotting.plot_surf_stat_map` function is used
to plot the resulting statistical map on the pial surface.
See also :ref:`for a similar example but using volumetric input data
<sphx_glr_auto_examples_03_connectivity_plot_seed_to_voxel_correlation.py>`.
.. seealso::
See :ref:`plotting` for more details on plotting tools.
:ref:`for a similar example but using volumetric input data
<sphx_glr_auto_examples_03_connectivity_plot_seed_to_voxel_correlation.py>`.
See :ref:`plotting` for more details on plotting tools.
"""

# %%
Expand Down Expand Up @@ -271,7 +273,7 @@
# References
# ----------
#
# .. footbibliography::
# .. footbibliography::


# sphinx_gallery_thumbnail_number = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
display = plotting.plot_stat_map(
img,
cut_coords=coords,
colorbar=False,
colorbar=True,
cmap="inferno",
title="Showing one specific network",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@
# Let us plot the second level :term:`contrast` at the computed thresholds.
from nilearn.plotting import plot_stat_map, show

cut_coords = [10, -5, 10]

plot_stat_map(
z_map,
threshold=threshold,
colorbar=True,
title="Group-level association between motor activity \n"
"and reading fluency (fdr=0.05)",
cut_coords=cut_coords,
draw_cross=False,
)

show()
Expand All @@ -110,7 +114,7 @@

# %%
# Let us plot the (corrected) negative log p-values for the parametric test
cut_coords = [38, -17, -3]

# Since we are plotting negative log p-values and using a threshold equal to 1,
# it corresponds to corrected p-values lower than 10%, meaning that there
# is less than 10% probability to make a single false discovery
Expand All @@ -127,6 +131,9 @@
cut_coords=cut_coords,
threshold=threshold,
title=title,
vmin=threshold,
cmap="inferno",
draw_cross=False,
)
show()

Expand Down Expand Up @@ -158,6 +165,9 @@
cut_coords=cut_coords,
threshold=threshold,
title=title,
vmin=threshold,
cmap="inferno",
draw_cross=False,
)
show()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
},
"outputs": [],
"source": [
"from nilearn.image import iter_img\nfrom nilearn.plotting import plot_stat_map, show\n\nfor i, cur_img in enumerate(iter_img(canica_components_img)):\n plot_stat_map(\n cur_img,\n display_mode=\"z\",\n title=f\"IC {int(i)}\",\n cut_coords=1,\n colorbar=False,\n )"
"from nilearn.image import iter_img\nfrom nilearn.plotting import plot_stat_map, show\n\nfor i, cur_img in enumerate(iter_img(canica_components_img)):\n plot_stat_map(\n cur_img,\n display_mode=\"z\",\n title=f\"IC {int(i)}\",\n cut_coords=1,\n vmax=0.05,\n vmin=-0.05,\n colorbar=False,\n )\n\n\nshow()"
]
},
{
Expand Down Expand Up @@ -137,7 +137,7 @@
},
"outputs": [],
"source": [
"for i, cur_img in enumerate(iter_img(dictlearning_components_img)):\n plot_stat_map(\n cur_img,\n display_mode=\"z\",\n title=f\"Comp {int(i)}\",\n cut_coords=1,\n colorbar=False,\n )"
"for i, cur_img in enumerate(iter_img(dictlearning_components_img)):\n plot_stat_map(\n cur_img,\n display_mode=\"z\",\n title=f\"Comp {int(i)}\",\n cut_coords=1,\n vmax=0.1,\n vmin=-0.1,\n colorbar=False,\n )"
]
},
{
Expand Down Expand Up @@ -169,7 +169,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## References\n\n .. footbibliography::\n\n"
"## References\n\n.. footbibliography::\n\n"
]
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 498e08f

Please sign in to comment.