updated imshow to optionally accept multiple images and show side by side using subplots
@@ -6,6 +6,9 @@ from mpl_toolkits.mplot3d.art3d import Poly3DCollection
def imshow(im, ind=None, axis=None):
r"""
Convenient wrapper for matplotlib's ``imshow``.
+def imshow(*im, ind=None, axis=None):
+ r"""
+ Convenience wrapper for matplotlib's ``imshow``.
This automatically:
* slices a 3D image in the middle of the last axis
@@ -15,23 +18,32 @@ def imshow(im, ind=None, axis=None):
Parameters
----------
im : ND-array
- The image to show. Can be 2D or 3D. If 2D then all other arguments
- are ignored.
+ The 2D or 3D image (or images) to show. If 2D then all other
+ arguments are ignored.
ind : int
The slice to show if ``im`` is 3D. If not given then the middle of
the image is used.
axis : int
The axis to show if ``im`` is 3D. If not given, then the last
axis of the image is used, so an 'xy' slice is shown.
+
+ Note
+ ----
+ ``im`` can also be a series of unnamed arguments, in which case all
+ received images will be shown using ``subplot``.
"""
- if im.ndim == 3:
+ if not isinstance(im, tuple):
+ im = tuple([im])
+ for i, image in enumerate(im):
+ if image.ndim == 3:
if axis is None:
axis = 2
if ind is None:
- ind = int(im.shape[axis]/2)
- im = im.take(indices=ind, axis=axis)
- im = np.ma.array(im, mask=im == 0)
- fig = plt.imshow(im, origin='xy')
+ ind = int(image.shape[axis]/2)
+ image = image.take(indices=ind, axis=axis)
+ image = np.ma.array(image, mask=image == 0)
+ fig = plt.subplot(1, len(im), i+1)
+ plt.imshow(image, origin='xy')
return fig
