1

I'm new to coding, so if I'm completely wrong just tell me.

I want to plot 25 slices of a brain scan using nilearn. These 25 slices should go along the z axis in steps of value=2. I want to use subplots to present them using subplots.

Here is what I have so far:

cuts = np.arange(-25,25,2)
fig, (axes1,axes2,axes3,axes4,axes5) = plt.subplots(5,1, figsize=(10,10))

for axes in [axes1,axes2,axes3,axes4,axes5]:
    for slc in cuts:
        plotting.plot_stat_map(rsn_four, display_mode='z', axes=axes, cut_coords=[slc], threshold=2)
plt.show()

'rsn_four' is a 3D Nifti file of a BOLD scan.

Output:

I think one of my biggest problem is, that I do not know how to implement, that per axis I want 5 values of the np.arange() and then bring it to the next axis continuing the counting.

If I missed some info, let me know, this is my first post here!

Lightnjer
  • 27
  • 5

1 Answers1

0

The enumerate built-in may be helpful here in getting only the correct indices from cuts that you would want per image

cuts = np.arange(-25,25,2)
fig, (axes1,axes2,axes3,axes4,axes5) = plt.subplots(5,1, figsize=(10,10))

for num, axes in enumerate([axes1,axes2,axes3,axes4,axes5]):
    for slc in cuts[num:num+5]:
        plotting.plot_stat_map(rsn_four, display_mode='z', axes=axes, cut_coords=[slc], threshold=2)
plt.show()
S.Chauhan
  • 156
  • 2
  • 8