ants.plotting.plot_grid

plot_grid(images, slices=None, axes=2, figsize=1.0, rpad=0, cpad=0, vmin=None, vmax=None, colorbar=True, cmap='Greys_r', title=None, tfontsize=20, title_dx=0, title_dy=0, rlabels=None, rfontsize=14, rfontcolor='white', rfacecolor='black', clabels=None, cfontsize=14, cfontcolor='white', cfacecolor='black', filename=None, dpi=400, transparent=True, **kwargs)[source]

Plot a collection of images in an arbitrarily-defined grid

Matplotlib named colors: https://matplotlib.org/examples/color/named_colors.html

Parameters:
  • images (list of ANTsImage types) – image(s) to plot. if one image, this image will be used for all grid locations. if multiple images, they should be arrange in a list the same shape as the gridsize argument.

  • slices (int or list of integers) – slice indices to plot if one integer, this slice index will be used for all images if multiple integers, they should be arranged in a list the same shape as the gridsize argument

  • axes (int or list of integers) – axis or axes along which to plot image slices if one integer, this axis will be used for all images if multiple integers, they should be arranged in a list the same shape as the gridsize argument

Example

>>> import ants
>>> import numpy as np
>>> mni1 = ants.image_read(ants.get_data('mni'))
>>> mni2 = mni1.smooth_image(1.)
>>> mni3 = mni1.smooth_image(2.)
>>> mni4 = mni1.smooth_image(3.)
>>> images = np.asarray([[mni1, mni2],
...                      [mni3, mni4]])
>>> slices = np.asarray([[100, 100],
...                      [100, 100]])
>>> ants.plot_grid(images=images, slices=slices, title='2x2 Grid')
>>> images2d = np.asarray([[mni1.slice_image(2,100), mni2.slice_image(2,100)],
...                        [mni3.slice_image(2,100), mni4.slice_image(2,100)]])
>>> ants.plot_grid(images=images2d, title='2x2 Grid Pre-Sliced')
>>> ants.plot_grid(images.reshape(1,4), slices.reshape(1,4), title='1x4 Grid')
>>> ants.plot_grid(images.reshape(4,1), slices.reshape(4,1), title='4x1 Grid')
>>> # Padding between rows and/or columns
>>> ants.plot_grid(images, slices, cpad=0.02, title='Col Padding')
>>> ants.plot_grid(images, slices, rpad=0.02, title='Row Padding')
>>> ants.plot_grid(images, slices, rpad=0.02, cpad=0.02, title='Row and Col Padding')
>>> # Adding plain row and/or column labels
>>> ants.plot_grid(images, slices, title='Adding Row Labels', rlabels=['Row #1', 'Row #2'])
>>> ants.plot_grid(images, slices, title='Adding Col Labels', clabels=['Col #1', 'Col #2'])
>>> ants.plot_grid(images, slices, title='Row and Col Labels',
                   rlabels=['Row 1', 'Row 2'], clabels=['Col 1', 'Col 2'])
>>> # Making a publication-quality image
>>> images = np.asarray([[mni1, mni2, mni2],
...                      [mni3, mni4, mni4]])
>>> slices = np.asarray([[100, 100, 100],
...                      [100, 100, 100]])
>>> axes = np.asarray([[0, 1, 2],
                       [0, 1, 2]])
>>> ants.plot_grid(images, slices, axes, title='Publication Figures with ANTsPy',
                   tfontsize=20, title_dy=0.03, title_dx=-0.04,
                   rlabels=['Row 1', 'Row 2'],
                   clabels=['Col 1', 'Col 2', 'Col 3'],
                   rfontsize=16, cfontsize=16)