Multi-subjects figures with nilearn.plotting

Hi,
I was wondering if it is possible to have multi-subjects plots using the nilearn.plotting functions.
Specifically, I want to create an image that allow me to quickly check the alignment of some labels to the structural MRI of a subject.
I can of course do the following

import nilearn.plotting
display = plotting.plot_anat(“this_subject_t1.nii”)
display.add_overlay(“this_subject_labels.nii”)
plotting.show()

However, I have a couple undred subjects, and I would like to create a figure with all subjects together. Any suggestion ?

Hi @fednem,

This looks like a job for subplots! Here is a minimal example that should give you inspiration to do what you want:

from nilearn import plotting
from nilearn import datasets
import matplotlib.pyplot as plt

# download some example data
haxby_dataset = datasets.fetch_haxby()

# create a figure with multiple axes to plot each anatomical image
fig, axes = plt.subplots(nrows=5, ncols=2, figsize=(14, 20))

# axes is a 2 dimensional numpy array
for ax in axes.flatten():
    display = plotting.plot_anat(haxby_dataset.anat[0], axes=ax)

# save the output figure with all the anatomical images
fig.savefig("my_test_img.png")

Let me know if you have additional questions, or if anyone else has another solution.
James

Thanks a lot for the tip @jdkent !
It works like a charm !

1 Like

For the record, I find it much easier to piece figures together after saving them, than with matplotlib. I use typically either an HTML page, or a PDF (generated with LaTeX or restructured text and rst2pdf).

1 Like

MANAGED BY INCF